public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA] Fix leak in forward-search
@ 2018-11-27 23:34 Philippe Waroquiers
  2018-11-29 15:42 ` Pedro Alves
  0 siblings, 1 reply; 7+ messages in thread
From: Philippe Waroquiers @ 2018-11-27 23:34 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

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-28  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.
---
 gdb/source.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/source.c b/gdb/source.c
index e295fbf49e..c75351e65f 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 ());
-- 
2.19.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-12-08 15:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-27 23:34 [RFA] Fix leak in forward-search Philippe Waroquiers
2018-11-29 15:42 ` Pedro Alves
2018-11-29 23:05   ` Philippe Waroquiers
2018-11-30 19:43     ` [PATCH] Merge forward-search/reverse-search, use gdb::def_vector, remove limit (Re: [RFA] Fix leak in forward-search) Pedro Alves
2018-11-30 20:42       ` Tom Tromey
2018-12-08 15:12         ` Pedro Alves
2018-12-02 16:57       ` Philippe Waroquiers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).