Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 73916 invoked by uid 500); 23 Aug 2001 08:54:12 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 73905 invoked from network); 23 Aug 2001 08:54:12 -0000 From: "Sander Striker" To: "Greg Stein" , Subject: Pools behaviour, WAS: RE: cvs commit: apr-util/test testdbm.c Date: Thu, 23 Aug 2001 11:04:45 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 In-Reply-To: <20010822203522.C16727@lyra.org> Importance: Normal X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N ... 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