Message ID | loom.20130307T103516-549@post.gmane.org |
---|---|
State | Not Applicable, archived |
Delegated to: | David Miller |
Headers | show |
> 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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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;
Fix memory leaks Signed-off-by: JB <jb.1234abcd@gmail.com> --- ping.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html