From: Tom Tromey <tromey@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: RFA: fix minor memory leak in symfile.c
Date: Sat, 13 Sep 2008 22:53:00 -0000 [thread overview]
Message-ID: <m3r67nu0bn.fsf@fleche.redhat.com> (raw)
In-Reply-To: <20080913223455.GB19625@adacore.com> (Joel Brobecker's message of "Sat\, 13 Sep 2008 15\:34\:55 -0700")
>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:
Joel> The C standard requires that free does nothing when passed a NULL
Joel> pointer. So unless we're building GDB with a screwy C compiler,
Joel> it's strictly equivalent to calling free.
My understanding is that on all systems in active use, free(NULL)
works fine. Jim Meyering recently removed if (x) free (x) from a
bunch of GNU programs...
Joel> Still, I think it'd be nice to get rid of these. In desperate
Joel> situations, one might want to locally hack these to track memory
Joel> issues...
Here's the patch. I'm regtesting it now.
I also changed a use of asprintf, because gdbint.texinfo clearly
states that this function is not to be used. (It is the only use in
gdb.)
Ok if it succeeds?
Note that, if you should ever actually have to do this, you should
expect to have to fix gdb first anyway. In the absence of enforcement
I am sure that more uses of free will sneak in.
Tom
2008-09-13 Tom Tromey <tromey@redhat.com>
* varobj.c (varobj_set_display_format): Use xfree.
* tracepoint.c (stringify_collection_list): Use xfree.
* remote-fileio.c (remote_fileio_reset): Use xfree.
* mipsread.c (read_alphacoff_dynamic_symtab): Use xfree.
* dfp.c (decimal_from_floating): Use xfree, xstrprintf. Don't use
asprintf.
* cp-support.c (mangled_name_to_comp): Use xfree.
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index df48f60..f50d8fd 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -167,7 +167,7 @@ mangled_name_to_comp (const char *mangled_name, int options,
if (ret == NULL)
{
- free (demangled_name);
+ xfree (demangled_name);
return NULL;
}
diff --git a/gdb/dfp.c b/gdb/dfp.c
index 9816d27..bbaf9aa 100644
--- a/gdb/dfp.c
+++ b/gdb/dfp.c
@@ -235,16 +235,12 @@ void
decimal_from_floating (struct value *from, gdb_byte *to, int len)
{
char *buffer;
- int ret;
- ret = asprintf (&buffer, "%.30" DOUBLEST_PRINT_FORMAT,
- value_as_double (from));
- if (ret < 0)
- error (_("Error in memory allocation for conversion to decimal float."));
+ buffer = xstrprintf ("%.30" DOUBLEST_PRINT_FORMAT, value_as_double (from));
decimal_from_string (to, len, buffer);
- free (buffer);
+ xfree (buffer);
}
/* Converts a decimal float of LEN bytes to a double value. */
diff --git a/gdb/mipsread.c b/gdb/mipsread.c
index fdd8634..1e88f81 100644
--- a/gdb/mipsread.c
+++ b/gdb/mipsread.c
@@ -217,13 +217,13 @@ read_alphacoff_dynamic_symtab (struct section_offsets *section_offsets,
dyninfo_secsize = bfd_get_section_size (si.dyninfo_sect);
got_secsize = bfd_get_section_size (si.got_sect);
sym_secptr = xmalloc (sym_secsize);
- cleanups = make_cleanup (free, sym_secptr);
+ cleanups = make_cleanup (xfree, sym_secptr);
str_secptr = xmalloc (str_secsize);
- make_cleanup (free, str_secptr);
+ make_cleanup (xfree, str_secptr);
dyninfo_secptr = xmalloc (dyninfo_secsize);
- make_cleanup (free, dyninfo_secptr);
+ make_cleanup (xfree, dyninfo_secptr);
got_secptr = xmalloc (got_secsize);
- make_cleanup (free, got_secptr);
+ make_cleanup (xfree, got_secptr);
if (!bfd_get_section_contents (abfd, si.sym_sect, sym_secptr,
(file_ptr) 0, sym_secsize))
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index 93665c9..05a78be 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -1398,7 +1398,7 @@ remote_fileio_reset (void)
}
if (remote_fio_data.fd_map)
{
- free (remote_fio_data.fd_map);
+ xfree (remote_fio_data.fd_map);
remote_fio_data.fd_map = NULL;
remote_fio_data.fd_map_size = 0;
}
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 671a63a..99bd17f 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1457,7 +1457,7 @@ stringify_collection_list (struct collection_list *list, char *string)
if (ndx == 0)
{
- free (str_list);
+ xfree (str_list);
return NULL;
}
else
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 3a0bf5e..12b644f 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -693,7 +693,7 @@ varobj_set_display_format (struct varobj *var,
if (varobj_value_is_changeable_p (var)
&& var->value && !value_lazy (var->value))
{
- free (var->print_value);
+ xfree (var->print_value);
var->print_value = value_get_print_value (var->value, var->format);
}
next prev parent reply other threads:[~2008-09-13 22:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-13 17:00 Tom Tromey
2008-09-13 17:08 ` Daniel Jacobowitz
2008-09-13 17:18 ` Joel Brobecker
2008-09-13 17:58 ` Tom Tromey
2008-09-13 22:35 ` Joel Brobecker
2008-09-13 22:53 ` Tom Tromey [this message]
2008-09-13 23:04 ` Joel Brobecker
2008-09-13 23:47 ` Mark Kettenis
2008-09-14 23:09 ` Thiago Jung Bauermann
2008-09-15 0:06 ` Tom Tromey
2008-09-18 1:04 ` Joel Brobecker
2008-09-18 2:31 ` Daniel Jacobowitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3r67nu0bn.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox