iputils: fix memory leaks
Subsystems (2)
PATCH 1/1 iputils: fix memory leaks
Fix memory leaks
Signed-off-by JB <[email protected]>
--- ping.c | 9 +++++++++ 1 file changed, 9 insertions(+)
ping.c +9 -0
@@ -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;
Quoted 1 line
Fix memory leaks
...
ping.c main(int argc, char **argv) · line 289
Quoted 5 lines
ping.c +4
-0+#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
Quoted 12 lines · David Laight <David.Laight <at> ACULAB.COM> writes:
Quoted 2 lines
Fix memory leaks
...
ping.c main(int argc, char **argv) · line 289
Quoted 5 lines
ping.c +4
-0+#ifdef USE_IDN +free (idn); + idn =NULL ; +#endif exit (2 );There is no point calling
free()beforeexit(), nor any need to free items that aren't allocated inside loops.
Quoted 1 line
David
A matter of good style ? Overzealous ?
Flame ?
http://stackoverflow.com/questions/654754/what-really-happens-when-you-dont-free-after-malloc
jb