Unix Technical Forum

How important is it to free() on run once programs?

This is a discussion on How important is it to free() on run once programs? within the lucky.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 ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > lucky.openbsd.tech

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-22-2008, 11:45 AM
Han Boetes
 
Posts: n/a
Default How important is it to free() on run once programs?

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:55 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com