Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn) Newsgroups: net.bugs.usg Subject: SVR2.0 -lmalloc bug fixes Message-ID: <11340@brl-tgr.ARPA> Date: Fri, 28-Jun-85 07:47:08 EDT Article-I.D.: brl-tgr.11340 Posted: Fri Jun 28 07:47:08 1985 Date-Received: Sat, 29-Jun-85 03:42:55 EDT Distribution: net Organization: Ballistic Research Lab Lines: 125 BUG FIXES for UNIX System V Release 2.0 libmalloc.a (-lmalloc), lines added or changed flagged with "DAG", lines omitted "...": /* @(#)malloc.c 1.5 */ ... char * malloc(nbytes) unsigned nbytes; { register struct header *blk; register unsigned nb; /* size of entire block we need */ char *sbrk(); /* on first call, initialize */ if (freeptr[0].nextfree == GROUND) { /* DAG -- clarify */ ... /* temporarily alter maxfast, to avoid infinite recursion */ maxfast = 0; holdhead = (struct holdblk **) malloc(sizeof(struct holdblk *)* (fastct + 1)); if (holdhead == 0) /* DAG -- bug fix */ return malloc(nbytes); /* DAG leave maxfast==0 */ for(i=1; i<=fastct; i++) { /* DAG -- cosmetic */ ... /* check that a very large request won't cause an inf. loop */ /* DAG NOTE -- following does not work on Gould due to cc bug */ /* DAG -- bug fix next line (casts were omitted): */ if ((char *)freeptr[1].nextblk - (char *)&freeptr[1] < nb) return NULL; { ... /* get memory */ if ((int)sbrk(nget) == -1) { /* DAG */ return NULL; } /* add to arena */ ... #endif if ((int)sbrk(nget) == -1) { /* DAG */ return NULL; } /* block must be word aligned */ ... assert(((int)newblk%ALIGNSZ) == 0); if ((int)sbrk(nget) == -1) { /* DAG */ return NULL; } /* combine with last block, put in arena */ ... CHECKQ; /* DAG -- following statement block added as bug fix: */ { register struct lblk *lblk = (struct lblk *)((char *)blk + minhead - MINHEAD); lblk->header.nextfree = CLRSMAL( lblk->header.nextfree ); } return (char *)blk + minhead; } ... void free(ptr) char *ptr; { register struct holdblk *holdblk; /* block holding blk */ register struct holdblk *oldhead; /* former head of the hold block queue containing blk's holder */ if ( ptr == NULL ) /* DAG -- added safety net */ return; /* DAG */ /* DAG -- bug fix: */ if (TESTSMAL(((struct lblk *)(ptr - MINHEAD))->header.holder)) { ... struct mallinfo mallinfo() { ... /* examine space in holding blks */ if (holdhead != 0) /* DAG -- bug fix */ for (i=fastct; i>0; i--) { /* loop thru ea. chain */ hblk = holdhead[i]; if (hblk != HGROUND) { /* do only if chain not empty */ /* DAG -- following statement moved, bug fix */ size = hblk->blksz + sizeof(struct lblk) - sizeof(int); do { /* loop thru 1 hold blk chain */ ... rstalloc() { /* struct header *temp; /* DAG -- unused */ /* temp = arena; /* DAG -- unused */ ... if(freeptr[0].nextfree == GROUND) return; /* DAG -- clarify */ brk(CLRBUSY(arena[1].nextblk)); freeptr[0].nextfree = GROUND; /* DAG -- clarify */ } #endif /*RSTALLOC*/