* [PATCH] iputils: fix memory leaks
@ 2013-03-07 9:52 jb
2013-03-07 10:06 ` David Laight
0 siblings, 1 reply; 3+ messages in thread
From: jb @ 2013-03-07 9:52 UTC (permalink / raw)
To: netdev
Fix memory leaks
Signed-off-by: JB <jb.1234abcd@gmail.com>
---
ping.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/ping.c b/ping.c
index c0366cd..04f5596 100644
--- a/ping.c
+++ b/ping.c
@@ -282,10 +282,15 @@ main(int argc, char **argv)
hp = gethostbyname(idn);
if (!hp) {
fprintf(stderr, "ping: unknown host %s\n", target);
+#ifdef USE_IDN
+ free(idn);
+ idn = NULL;
+#endif
exit(2);
}
#ifdef USE_IDN
free(idn);
+ idn = NULL;
#endif
memcpy(&whereto.sin_addr, hp->h_addr, 4);
#ifdef USE_IDN
@@ -301,6 +306,10 @@ main(int argc, char **argv)
hnamebuf[sizeof(hnamebuf) - 1] = 0;
#endif
hostname = hnamebuf;
+#ifdef USE_IDN
+ free(hnamebuf);
+ hnamebuf = NULL;
+#endif
}
if (argc > 1)
route[nroute++] = whereto.sin_addr.s_addr;
^ permalink raw reply related [flat|nested] 3+ messages in thread* RE: [PATCH] iputils: fix memory leaks 2013-03-07 9:52 [PATCH] iputils: fix memory leaks jb @ 2013-03-07 10:06 ` David Laight 2013-03-07 11:18 ` jb 0 siblings, 1 reply; 3+ messages in thread From: David Laight @ 2013-03-07 10:06 UTC (permalink / raw) To: jb, netdev > Fix memory leaks ... > +#ifdef USE_IDN > + free(idn); > + idn = NULL; > +#endif > exit(2); There is no point calling free() before exit(), nor any need to free items that aren't allocated inside loops. David ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iputils: fix memory leaks 2013-03-07 10:06 ` David Laight @ 2013-03-07 11:18 ` jb 0 siblings, 0 replies; 3+ messages in thread From: jb @ 2013-03-07 11:18 UTC (permalink / raw) To: netdev David Laight <David.Laight <at> ACULAB.COM> writes: > > > Fix memory leaks > ... > > +#ifdef USE_IDN > > + free(idn); > > + idn = NULL; > > +#endif > > exit(2); > > There is no point calling free() before exit(), nor any need > to free items that aren't allocated inside loops. > > David A matter of good style ? Overzealous ? Flame ? http://stackoverflow.com/questions/654754/what-really-happens-when-you-dont-free-after-malloc jb ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-03-07 11:18 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-03-07 9:52 [PATCH] iputils: fix memory leaks jb 2013-03-07 10:06 ` David Laight 2013-03-07 11:18 ` jb
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox