This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix leak in forward-search


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=95b1f9ac6b7de84b09580bdf2456955bcff86da1

commit 95b1f9ac6b7de84b09580bdf2456955bcff86da1
Author: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Date:   Wed Nov 28 00:22:29 2018 +0100

    Fix leak in forward-search
    
    Valgrind reports the below leak.
    Fix the leak by using xrealloc, even for the first allocation,
    as buf is static.
    
    ==29158== 5,888 bytes in 23 blocks are definitely lost in loss record 3,028 of 3,149
    ==29158==    at 0x4C2BE2D: malloc (vg_replace_malloc.c:299)
    ==29158==    by 0x41B557: xmalloc (common-utils.c:44)
    ==29158==    by 0x60B7D9: forward_search_command(char const*, int) (source.c:1563)
    ==29158==    by 0x40BA68: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1888)
    ==29158==    by 0x665300: execute_command(char const*, int) (top.c:630)
    ...
    
    gdb/ChangeLog
    2018-11-29  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
    
    	* source.c (forward_search_command): Fix leak by using
    	xrealloc even for the first allocation in the loop, as buf
    	is static.

Diff:
---
 gdb/ChangeLog | 6 ++++++
 gdb/source.c  | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1ec466d..d4749dc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-29  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+	* source.c (forward_search_command): Fix leak by using
+	xrealloc even for the first allocation in the loop, as buf
+	is static.
+
 2018-11-29  Rajendra SY  <rajendra.sy@gmail.com>
 
 	PR gdb/23093
diff --git a/gdb/source.c b/gdb/source.c
index e295fbf..c75351e 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1560,7 +1560,7 @@ forward_search_command (const char *regex, int from_tty)
       int cursize, newsize;
 
       cursize = 256;
-      buf = (char *) xmalloc (cursize);
+      buf = (char *) xrealloc (buf, cursize);
       p = buf;
 
       c = fgetc (stream.get ());


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]