Received: by taz.hyperreal.com (8.8.4/V2.0) id PAA01056; Fri, 7 Mar 1997 15:27:58 -0800 (PST) Received: from sierra.zyzzyva.com by taz.hyperreal.com (8.8.4/V2.0) with ESMTP id PAA01051; Fri, 7 Mar 1997 15:27:54 -0800 (PST) Received: from sierra (localhost [127.0.0.1]) by sierra.zyzzyva.com (8.8.5/8.8.2) with ESMTP id RAA16424 for ; Fri, 7 Mar 1997 17:28:44 -0600 (CST) Message-Id: <199703072328.RAA16424@sierra.zyzzyva.com> X-Mailer: exmh version 2.0gamma 1/27/96 To: new-httpd@hyperreal.com Subject: Re: memory management goof in alloc.c (fwd) In-reply-to: fielding's message of Fri, 07 Mar 1997 10:29:27 -0800. <9703071029.aa17249@paris.ics.uci.edu> X-uri: http://www.zyzzyva.com/ Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 07 Mar 1997 17:28:44 -0600 From: Randy Terbush Sender: new-httpd-owner@apache.org Precedence: bulk Reply-To: new-httpd@hyperreal.com +1 > > if (arr->nelts == arr->nalloc) { > >! int new_size = arr->nalloc * 2; > >! char *new_data; > >! > >! if (new_size == 0) ++new_size; > >! > >! new_data = pcalloc (arr->pool, arr->elt_size * new_size); > > In principle the patch is good, but I don't like the way it > sets new_size and then increments it. That bit of uglyness was > inherited from the other function, but I'd prefer to fix both > as in the following patch. > > .....Roy > > Index: alloc.c > =================================================================== > RCS file: /export/home/cvs/apache/src/alloc.c,v > retrieving revision 1.22 > diff -c -r1.22 alloc.c > *** alloc.c 1997/01/19 17:43:27 1.22 > --- alloc.c 1997/03/07 18:25:38 > *************** > *** 461,471 **** > void *push_array (array_header *arr) > { > if (arr->nelts == arr->nalloc) { > ! char *new_data = pcalloc (arr->pool, arr->nalloc * arr->elt_size * 2); > > memcpy (new_data, arr->elts, arr->nalloc * arr->elt_size); > arr->elts = new_data; > ! arr->nalloc *= 2; > } > > ++arr->nelts; > --- 461,474 ---- > void *push_array (array_header *arr) > { > if (arr->nelts == arr->nalloc) { > ! int new_size = (arr->nalloc <= 0) ? 1 : arr->nalloc * 2; > ! char *new_data; > ! > ! new_data = pcalloc (arr->pool, arr->elt_size * new_size); > > memcpy (new_data, arr->elts, arr->nalloc * arr->elt_size); > arr->elts = new_data; > ! arr->nalloc = new_size; > } > > ++arr->nelts; > *************** > *** 477,487 **** > int elt_size = dst->elt_size; > > if (dst->nelts + src->nelts > dst->nalloc) { > ! int new_size = dst->nalloc * 2; > char *new_data; > > - if (new_size == 0) ++new_size; > - > while (dst->nelts + src->nelts > new_size) > new_size *= 2; > > --- 480,488 ---- > int elt_size = dst->elt_size; > > if (dst->nelts + src->nelts > dst->nalloc) { > ! int new_size = (dst->nalloc <= 0) ? 1 : dst->nalloc * 2; > char *new_data; > > while (dst->nelts + src->nelts > new_size) > new_size *= 2; >