apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mladen Turk <mt...@apache.org>
Subject Re: Crash in apr_file_close() (Win32)
Date Mon, 21 Sep 2009 16:09:47 GMT
Just an update from the conversation I had with Yuri.

He confirmed that the APR crashes if build with VS2008.
(both debug and release version of msvcrt90(d).dll)
Now looking at the MSVCRT source for _close, I suspect
it crashes with VS2005 as well.

Since it doesn't crash if linked to msvcrt.dll I presume
the cause is the following comment:

<snip>
In order to avoid later segfaults with handle 'reuse',
we must protect against the case that a dup2'ed handle
is being closed, and invalidate the corresponding StdHandle
We also tell msvcrt when stdhandles are closed.
</snip>

Indeed the crash happens on second _close(1) call.
I presume the _close(x) should be called *only* if
the file was dup2'ed (at least according to the comment
in the code), so I'll try to figure out how to fix that
unless Bill has some other ideas or suggestions.



>
> The following simple code reproduces such error:
>
> int main(int a, char** b)
> {
> apr_pool_t * pool;
> apr_file_t *file1, *file2;
>
>
> apr_initialize();
> apr_pool_create(&pool, NULL);
>
> apr_file_open_stdout(&file1, pool);
> apr_file_open_stdout(&file2, pool);
>
> apr_file_puts("Hello World (1)\n", file1);
> apr_file_puts("Hello World (2)\n", file2);
>
> apr_file_close(file1);
> apr_file_close(file2); // <-- crash is here.
>
> apr_terminate();
>
> return(0);
> }
>

Regards
-- 
^TM


Mime
View raw message