home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!fitzgb
- From: fitzgb@mml0.meche.rpi.edu (Brian Fitzgerald)
- Subject: Re: Does free() really free?
- Message-ID: <hf1yh5=@rpi.edu>
- Summary: no
- Nntp-Posting-Host: mml0.meche.rpi.edu
- Organization: Rensselaer Polytechnic Institute, Troy, NY
- References: <9209051620.AA02618@ucbvax.Berkeley.EDU>
- Date: Sat, 5 Sep 1992 19:48:55 GMT
- Lines: 41
-
- Simon Marshall writes:
- > So, please could anyone tell me what is going on here? Does free()
- > actually free, and is the SZ column of ps reliable in any way? Or is
-
- malloc() uses the sbrk() system call to get more space when it needs
- it. free() performs no system calls, and merely frees the space for
- subsequent reuse by malloc.
-
- I base my comments on perusal of the malloc sources in wuarchive.wustl.edu:
- /archive/systems/unix/4.3bsd-reno/lib/libc/stdlib
-
- Brian
-
- void
- free(cp)
- void *cp;
- {
- register int size;
- register union overhead *op;
-
- if (cp == NULL)
- return;
- op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
- #ifdef DEBUG
- ASSERT(op->ov_magic == MAGIC); /* make sure it was in use */
- #else
- if (op->ov_magic != MAGIC)
- return; /* sanity */
- #endif
- #ifdef RCHECK
- ASSERT(op->ov_rmagic == RMAGIC);
- ASSERT(*(u_short *)((caddr_t)(op + 1) + op->ov_size) == RMAGIC);
- #endif
- size = op->ov_index;
- ASSERT(size < NBUCKETS);
- op->ov_next = nextf[size]; /* also clobbers ov_magic */
- nextf[size] = op;
- #ifdef MSTATS
- nmalloc[size]--;
- #endif
- }
-