You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Mladen Turk <mt...@apache.org> on 2007/12/11 12:45:17 UTC

Failing apr_pool_create in case apr_pools_initialized == 0

Hi,

I'd like to make sure the apr_pool_create(_ex)
returns error in case apr was terminated, meaning
apr_pool_terminate() was called and apr_pools_initialized is 0.

Seems we are missing that check in apr_pool_create_ex,
and I think APR_ENOMEM is correct error code we could
return in that case (or perhaps APR_EINVAL)

Comments?

Regards,
Mladen


Re: Failing apr_pool_create in case apr_pools_initialized == 0

Posted by Mladen Turk <mt...@apache.org>.
Sander Striker wrote:
> After apr_terminate() when calling any function, the behaviour is undefined.
> This is as expected.  I don't see a need to protect against that.
> 

Sure, but the same logic can then be applied to
the 'if (apr_initialized++)'
Seems we after all honor multiple invocations of
both apr_initialize/apr_terminate, etc.

Threaded applications might be unaware that other
thread called apr_terminate and that this call will
actually cause the apr to terminate.
So since one cannot be sure that the call to the
apr_terminate() will terminate the apr, application
using apr will need to duplicate the logic in
apr_initialize/apr_terminate for assuring it'a a singleton
and at which time it is safe to call the apr_pool_create,
and in which it is not.

Anyhow, it's a simple compare against an int, so
a completely benign operation, but allowing to
not core dump in threaded environment.

Regards,
Mladen


Re: Failing apr_pool_create in case apr_pools_initialized == 0

Posted by Mladen Turk <mt...@apache.org>.
Sander Striker wrote:
> After apr_terminate() when calling any function, the behaviour is undefined.
> This is as expected.  I don't see a need to protect against that.
> 

Just to make sure what I'm talking about ;)

Index: apr_pools.c
===================================================================
--- apr_pools.c	(revision 603246)
+++ apr_pools.c	(working copy)
@@ -820,6 +820,13 @@

      *newpool = NULL;

+    if (!apr_pools_initialized) {
+        if (abort_fn)
+            abort_fn(APR_ENOMEM);
+
+        return APR_ENOMEM;
+    }
+
      if (!parent)
          parent = global_pool;



Regards,
Mladen


Re: Failing apr_pool_create in case apr_pools_initialized == 0

Posted by Sander Striker <s....@striker.nl>.
After apr_terminate() when calling any function, the behaviour is undefined.
This is as expected.  I don't see a need to protect against that.

Sander

On 12/11/07, Mladen Turk <mt...@apache.org> wrote:
> Hi,
>
> I'd like to make sure the apr_pool_create(_ex)
> returns error in case apr was terminated, meaning
> apr_pool_terminate() was called and apr_pools_initialized is 0.
>
> Seems we are missing that check in apr_pool_create_ex,
> and I think APR_ENOMEM is correct error code we could
> return in that case (or perhaps APR_EINVAL)
>
> Comments?
>
> Regards,
> Mladen
>
>