This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Patch: FYI: fix some trivial memory leaks
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 18 Aug 2009 10:16:57 -0600
- Subject: Patch: FYI: fix some trivial memory leaks
- Reply-to: Tom Tromey <tromey at redhat dot com>
I'm checking this in.
I was running valgrind and I noticed a few small memory leaks. These
all occur because add_setshow_cmd_full makes a copy of its documentation
strings. So, callers that allocate to compute the documentation should
free it.
There are still little leaks here, because nothing ever frees a commands
documentation. This means the new language command code leaks memory --
about 4K. I didn't try to fix this.
Tom
2009-08-18 Tom Tromey <tromey@redhat.com>
* utils.c (add_internal_problem_command): Free set_doc and
show_doc.
* remote.c (add_packet_config_cmd): Free set_doc and show_doc.
* language.c (add_language): Free language_set_doc.
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.89
diff -u -r1.89 language.c
--- language.c 14 Aug 2009 00:32:32 -0000 1.89
+++ language.c 18 Aug 2009 16:14:23 -0000
@@ -884,7 +884,7 @@
/* For the "set language" command. */
static char **language_names = NULL;
/* For the "help set language" command. */
- static char *language_set_doc = NULL;
+ char *language_set_doc = NULL;
int i;
struct ui_file *tmp_stream;
@@ -943,7 +943,6 @@
languages[i]->la_name + 1);
}
- xfree (language_set_doc);
language_set_doc = ui_file_xstrdup (tmp_stream, NULL);
ui_file_delete (tmp_stream);
@@ -955,6 +954,8 @@
set_language_command,
show_language_command,
&setlist, &showlist);
+
+ xfree (language_set_doc);
}
/* Iterate through all registered languages looking for and calling
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.369
diff -u -r1.369 remote.c
--- remote.c 14 Aug 2009 00:32:32 -0000 1.369
+++ remote.c 18 Aug 2009 16:14:24 -0000
@@ -865,6 +865,9 @@
set_remote_protocol_packet_cmd,
show_remote_protocol_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist);
+ /* The command code copies the documentation strings. */
+ xfree (set_doc);
+ xfree (show_doc);
/* set/show remote NAME-packet {auto,on,off} -- legacy. */
if (legacy)
{
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.218
diff -u -r1.218 utils.c
--- utils.c 14 Aug 2009 00:32:32 -0000 1.218
+++ utils.c 18 Aug 2009 16:14:24 -0000
@@ -1098,6 +1098,9 @@
set_cmd_list,
show_cmd_list);
+ xfree (set_doc);
+ xfree (show_doc);
+
set_doc = xstrprintf (_("\
Set whether GDB should create a core file of GDB when %s is detected"),
problem->name);
@@ -1114,6 +1117,9 @@
NULL, /* showfunc */
set_cmd_list,
show_cmd_list);
+
+ xfree (set_doc);
+ xfree (show_doc);
}
/* Print the system error message for errno, and also mention STRING