This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] valprint.c (read_string): Rework clean-up logic.
- From: Phil Muldoon <pmuldoon at redhat dot com>
- To: tromey at redhat dot com
- Cc: gdb-patches at sourceware dot org
- Date: Fri, 27 Feb 2009 21:13:24 +0000
- Subject: Re: [patch] valprint.c (read_string): Rework clean-up logic.
- References: <49A82F5C.9000801@redhat.com> <m37i3b676v.fsf@fleche.redhat.com>
Tom Tromey wrote:
Phil> + old_chain = make_cleanup (xfree_gdb_byte, buffer);
... and you can just s/xfree_gdb_byte/free_current_contents/ here.
It is ok with that change. Thanks.
Tom
Done. I attached the modified patch for reference.
Index: valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- valprint.c 5 Feb 2009 12:16:25 -0000 1.79
+++ valprint.c 27 Feb 2009 19:33:06 -0000 1.80
@@ -1226,13 +1226,14 @@
some error, such as bumping into the end of the address space. */
found_nul = 0;
- old_chain = make_cleanup (null_cleanup, 0);
+ *buffer = NULL;
+
+ old_chain = make_cleanup (free_current_contents, buffer);
if (len > 0)
{
*buffer = (gdb_byte *) xmalloc (len * width);
bufptr = *buffer;
- old_chain = make_cleanup (xfree, *buffer);
nfetch = partial_memory_read (addr, bufptr, len * width, &errcode)
/ width;
@@ -1243,8 +1244,6 @@
{
unsigned long bufsize = 0;
- *buffer = NULL;
-
do
{
QUIT;
@@ -1253,13 +1252,9 @@
if (*buffer == NULL)
*buffer = (gdb_byte *) xmalloc (nfetch * width);
else
- {
- discard_cleanups (old_chain);
- *buffer = (gdb_byte *) xrealloc (*buffer,
- (nfetch + bufsize) * width);
- }
+ *buffer = (gdb_byte *) xrealloc (*buffer,
+ (nfetch + bufsize) * width);
- old_chain = make_cleanup (xfree, *buffer);
bufptr = *buffer + bufsize * width;
bufsize += nfetch;