This is a discussion on Re: How important is it to free() on run once programs? within the mailing.openbsd.tech forums, part of the OpenBSD category; --> On Fri, Aug 26, 2005 at 12:44:37PM +0200, Han Boetes wrote: > Hi, > > I was looking for ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Fri, Aug 26, 2005 at 12:44:37PM +0200, Han Boetes wrote: > Hi, > > I was looking for an example of a cleanup with free() while > running into a fatal error which causes a direct errx() etc. > Don't cleanup on error pathes that exit the program. Exit does that for you and doing free() in case of errors may help heap overflows. > Not that I found it, but I found in df a malloc() without a > free(). Now I wonder how important it is to free() for a oneshot > program like df. > It may make sense for some oneshot programs to clean up allocations during runtime to keep the memory footprint low. There is no need to cleanup before any kind of exit (or exec). > If it is important I'd like to suggest this patch: > > Index: df.c > ================================================== ================= > RCS file: /cvs/src/bin/df/df.c,v > retrieving revision 1.43 > diff -u -p -r1.43 df.c > --- df.c 20 Feb 2005 01:34:56 -0000 1.43 > +++ df.c 26 Aug 2005 10:26:43 -0000 > @@ -118,8 +118,10 @@ main(int argc, char *argv[]) > Pflag = 1; > break; > case 't': > - if (typelist != NULL) > + if (typelist != NULL) { > + free(typelist); > errx(1, "only one -t option may be specified."); > + } > maketypelist(optarg); > break; > default: > @@ -188,6 +190,9 @@ main(int argc, char *argv[]) > else > bsdprint(mntbuf, mntsize, maxwidth); > } > + > + if (typelist != NULL) > + free(typelist); > > exit(mntsize ? 0 : 1); > } > > In both cases some sort of exit is called and so the cleanup is done automaticaly. -- :wq Claudio |
| Thread Tools | |
| Display Modes | |
|
|