apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject Re: Changing the order of cleanup for some core objects
Date Mon, 21 Jul 2008 09:34:25 GMT
On Mon, Jul 21, 2008 at 09:24:09AM +0200, Mladen Turk wrote:
...
> Socket created with S = apr_socket_create(P) registers its
> cleanup for pool P. The call for apr_socket_close(S) merely
> calls that cleanup causing the underlaying OS socket to get closed.
>
> ...
> S = apr_socket_create(P)
> ... do something
> ... with socket
> apr_socket_close(S) -> calls socket_cleanup(S)
> ...
>
> However if the apr_pool_destroy(P) gets called before
> apr_socket_close call (somebody rise the signal, etc..)
> the apr_pool_destroy call will cause the socket_cleanup(S)
> call and the apr_socket_close(S) will be no-op , and everything
> will behave as expected.

1) Any operation on S after P is destroyed has undefined behaviour, 
including calling apr_socket_close(S).  If that doesn't crash and burn 
with the current implementation it is pure chance.

2) No APR function is defined to be async-signal-safe, calling 
apr_pool_destroy(P) from a signal handler is liable to crash and burn 
regardless of how you change the cleanup ordering.

joe

Mime
View raw message