Index: gdb/valprint.c =================================================================== RCS file: /cvs/src/src/gdb/valprint.c,v retrieving revision 1.79 diff -u -r1.79 valprint.c --- gdb/valprint.c 5 Feb 2009 12:16:25 -0000 1.79 +++ gdb/valprint.c 27 Feb 2009 17:55:46 -0000 @@ -1177,6 +1177,15 @@ return (nread); } +/* Local clean-up for a gdb_byte buffer pointed to via double + indirection. This function is used in read_string. */ +static void +xfree_gdb_byte (void *buffer) +{ + gdb_byte **pointer = buffer; + xfree (*pointer); +} + /* Read a string from the inferior, at ADDR, with LEN characters of WIDTH bytes each. Fetch at most FETCHLIMIT characters. BUFFER will be set to a newly allocated buffer containing the string, which the caller is responsible to @@ -1226,13 +1235,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 (xfree_gdb_byte, 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 +1253,6 @@ { unsigned long bufsize = 0; - *buffer = NULL; - do { QUIT; @@ -1253,13 +1261,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;