dgaudet 98/05/05 23:09:21
Modified: src/main alloc.c Log: psprintf: fix a memory leak -- need to block alarms the whole time the block is being "abused"... easier to do that than it is to massage p->last each time we have to get a new block. fix a bug in psprintf_flush, it wouldn't copy properly when moving to a new block fix compile errors when compiling with ALLOC_USE_MALLOC Revision Changes Path 1.89 +7 -11 apache-1.3/src/main/alloc.c Index: alloc.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/alloc.c,v retrieving revision 1.88 retrieving revision 1.89 diff -u -r1.88 -r1.89 --- alloc.c 1998/04/15 17:09:28 1.88 +++ alloc.c 1998/05/06 06:09:20 1.89 @@ -55,7 +55,6 @@ * */ - /* * Resource allocation code... the code here is responsible for making * sure that nothing leaks. @@ -799,7 +798,7 @@ int size; char *ptr; - size = ps->vbuff.curpos - ps->base; + size = (char *)ps->vbuff.curpos - ps->base; ptr = realloc(ps->base, 2*size); if (ptr == NULL) { fputs("Ouch! Out of memory!\n", stderr); @@ -820,25 +819,20 @@ cur_len = strp - blok->h.first_avail; /* must try another blok */ - ap_block_alarms(); (void) ap_acquire_mutex(alloc_mutex); nblok = new_block(2 * cur_len); (void) ap_release_mutex(alloc_mutex); - ap_unblock_alarms(); - memcpy(nblok->h.first_avail, strp, cur_len); - strp = nblok->h.first_avail + cur_len; - ps->vbuff.curpos = strp; + memcpy(nblok->h.first_avail, blok->h.first_avail, cur_len); + ps->vbuff.curpos = nblok->h.first_avail + cur_len; ps->vbuff.endpos = nblok->h.endp - 1; /* did we allocate the current blok? if so free it up */ if (ps->got_a_new_block) { debug_fill(blok->h.first_avail, blok->h.endp - blok->h.first_avail); - ap_block_alarms(); (void) ap_acquire_mutex(alloc_mutex); blok->h.next = block_freelist; block_freelist = blok; (void) ap_release_mutex(alloc_mutex); - ap_unblock_alarms(); } ps->blok = nblok; ps->got_a_new_block = 1; @@ -865,7 +859,7 @@ *ps.vbuff.curpos++ = '\0'; ptr = ps.base; /* shrink */ - ptr = realloc(ptr, ps.vbuff.curpos - ptr); + ptr = realloc(ptr, (char *)ps.vbuff.curpos - (char *)ptr); if (ptr == NULL) { fputs("Ouch! Out of memory!\n", stderr); exit(1); @@ -879,9 +873,10 @@ char *strp; int size; + ap_block_alarms(); ps.blok = p->last; ps.vbuff.curpos = ps.blok->h.first_avail; - ps.vbuff.endpos = ps.blok->h.endp - 1; + ps.vbuff.endpos = ps.blok->h.endp - 1; /* save one for NUL */ ps.got_a_new_block = 0; ap_vformatter(psprintf_flush, &ps.vbuff, fmt, ap); @@ -902,6 +897,7 @@ ps.blok->h.owning_pool = p; #endif } + ap_unblock_alarms(); return strp; #endif