apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sander Striker" <stri...@apache.org>
Subject Pools behaviour, WAS: RE: cvs commit: apr-util/test testdbm.c
Date Thu, 23 Aug 2001 09:04:45 GMT
...
Ian>>   @@ -176,17 +180,21 @@
Ian>>        char *op;
Ian>>        int n;
Ian>>        char *line;
Ian>>   +    const char *use1;
Ian>>   +    const char *use2;
Ian>>    #ifdef TIME
Ian>>        long start;
Ian>>        extern long time();
Ian>>    #endif
Ian>>
Ian>>   -    if (apr_dbm_open(&db, file, act->flags, APR_OS_DEFAULT, pool)
Ian>>   -        != APR_SUCCESS)
Ian>>   -        oops("cannot open: %s", file);
Ian>>
Ian>>   -    if ((line = (char *) malloc(LINEMAX)) == NULL)
Ian>>   -        oops("%s: cannot get memory", "line alloc");
Ian>>   +    rv = apr_dbm_open(&db, file, act->flags, APR_OS_DEFAULT, pool);
Ian>>   +    if (rv != APR_SUCCESS)
Ian>>   +        oops(db, rv, "cannot open: %s", file);
Ian>>   +
Ian>>   +    if ((line = (char *) apr_palloc(pool,LINEMAX)) == NULL) {
Ian>>   +        oops(NULL, APR_EGENERAL, "%s: cannot get memory", "line
alloc");
Ian>>   +    }

Greg> apr_palloc() will never return NULL. No need for such a complex test.

It won't?  You mean that in httpd there is always an abortfunc present?
>From apr_pools.c:malloc_block():

    blok = (union block_hdr *) DO_MALLOC(size + sizeof(union block_hdr));
    if (blok == NULL) {
        /* ### keep this fprintf here? */
        fprintf(stderr, "Ouch!  malloc failed in malloc_block()\n");
        if (abortfunc != NULL) {
            (void) (*abortfunc)(APR_ENOMEM);
        }
        return NULL;
    }

And from apr_pools.c:apr_palloc():

    blok = new_block(size, a->apr_abort);
    a->last->h.next = blok;
    a->last = blok;
#ifdef APR_POOL_DEBUG
    blok->h.owning_pool = a;
#endif

#if APR_HAS_THREADS
    if (alloc_mutex) {
        apr_lock_release(alloc_mutex);
    }
#endif

    first_avail = blok->h.first_avail;
    blok->h.first_avail += size;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    return (void *) first_avail;
#endif
}

Oh, I see, you are saying that _without_ an abort
function it will segfault due to the marked line?

Is this reasonable behaviour?  I mean a simple
change to:

    if ((blok = new_block(size, a->apr_abort)) == NULL)
        return NULL;

might be more intuitive than having it segfault in
apr_palloc IMHO.


Sander


Mime
View raw message