Joe Orton
Mon, 21 Jul 2008 02:34:59 -0700
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