From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: gdb-patches@sourceware.org
Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Subject: [RFA] Fix leak in forward-search
Date: Tue, 27 Nov 2018 23:34:00 -0000 [thread overview]
Message-ID: <20181127233328.5164-1-philippe.waroquiers@skynet.be> (raw)
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
next reply other threads:[~2018-11-27 23:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-27 23:34 Philippe Waroquiers [this message]
[not found] ` <3cf960b8-ff82-0670-fa90-c94d78573bfe@redhat.com>
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
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=20181127233328.5164-1-philippe.waroquiers@skynet.be \
--to=philippe.waroquiers@skynet.be \
--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