This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [commit] fix memory leak in maintenance_do_deprecate
- From: Michael Snyder <msnyder at vmware dot com>
- To: Pedro Alves <pedro at codesourcery dot com>
- Cc: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Wed, 02 Mar 2011 17:16:07 -0800
- Subject: Re: [commit] fix memory leak in maintenance_do_deprecate
- References: <4D69A236.6070102@vmware.com> <201102271710.21629.pedro@codesourcery.com>
Pedro Alves wrote:
On Sunday 27 February 2011 01:00:38, Michael Snyder wrote:
+ /* If we get here, don't leak! */
+ if (replacement != NULL)
FYI, checks against NULL are not necessary, as xfree/free
is always safe with a NULL argument. IMO, the comment
adds more distraction that value, so I'd not have added
it (if you see an xfree, it's obvious you're guarding
against a leak).
+ xfree (replacement);
OK, as you suggest (attached, committed).
2011-03-02 Michael Snyder <msnyder@vmware.com>
* maint.c (maintenance_do_deprecate): No need to check for NULL.
Index: maint.c
===================================================================
RCS file: /cvs/src/src/gdb/maint.c,v
retrieving revision 1.83
diff -u -p -u -p -r1.83 maint.c
--- maint.c 27 Feb 2011 00:59:07 -0000 1.83
+++ maint.c 3 Mar 2011 01:14:09 -0000
@@ -644,9 +644,7 @@ maintenance_do_deprecate (char *text, in
cmd->flags |= MALLOCED_REPLACEMENT;
return;
}
- /* If we get here, don't leak! */
- if (replacement != NULL)
- xfree (replacement);
+ xfree (replacement);
}
/* Maintenance set/show framework. */