This is a discussion on How important is it to free() on run once programs? within the mailing.openbsd.tech forums, part of the OpenBSD category; --> Hi, I was looking for an example of a cleanup with free() while running into a fatal error which ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I was looking for an example of a cleanup with free() while running into a fatal error which causes a direct errx() etc. 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. 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); } # Han |