public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix leak due to assigning a xstrdup-ed string to the std::string gdb_datadir
@ 2019-10-01 6:57 Philippe Waroquiers
0 siblings, 0 replies; only message in thread
From: Philippe Waroquiers @ 2019-10-01 6:57 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cd7c32c36ae53c00e9b0731c58de37dc28b88fb6
commit cd7c32c36ae53c00e9b0731c58de37dc28b88fb6
Author: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Date: Sun Sep 29 18:26:23 2019 +0200
Fix leak due to assigning a xstrdup-ed string to the std::string gdb_datadir
Valgrind reports the following leak:
==32623== 56 bytes in 1 blocks are definitely lost in loss record 1,099 of 6,654
==32623== at 0x4835753: malloc (vg_replace_malloc.c:307)
==32623== by 0x25CF67: xmalloc (alloc.c:60)
==32623== by 0x65FBD9: xstrdup (xstrdup.c:34)
==32623== by 0x413D9E: captured_main_1(captured_main_args*) (main.c:553)
==32623== by 0x414FFA: captured_main (main.c:1172)
==32623== by 0x414FFA: gdb_main(captured_main_args*) (main.c:1197)
==32623== by 0x22531A: main (gdb.c:32)
Commit f2aec7f6d14 changed gdb_datadir to std::string.
So, xstrdup-ing the result of relocate_gdb_directory (returning a std::string)
is not needed and creates a leak.
Fix the leak by removing the xstrdup and the not needed c_str ().
Also removes a useless conversion of gdb_datadir to std::string.
gdb/ChangeLog
2019-10-01 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* main.c (relocate_gdbinit_path_maybe_in_datadir): Remove std::string
conversion of gdb_datadir.
(captured_main_1): Remove xstrdup when assigning to gdb_datadir,
remove not needed c_str ().
Diff:
---
gdb/ChangeLog | 7 +++++++
gdb/main.c | 8 +++-----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1be7f4b..7285515 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2019-10-01 Philippe Waroquiers <philippe.waroquiers@skynet.be>
+
+ * main.c (relocate_gdbinit_path_maybe_in_datadir): Remove std::string
+ conversion of gdb_datadir.
+ (captured_main_1): Remove xstrdup when assigning to gdb_datadir,
+ remove not needed c_str ().
+
2019-09-30 Ali Tamur <tamur@google.com>
* dwarf2read.c (skip_one_die): Handle DW_FORM_strx forms.
diff --git a/gdb/main.c b/gdb/main.c
index 7fab8ff..14d9e79 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -214,8 +214,7 @@ relocate_gdbinit_path_maybe_in_datadir (const std::string& file)
size_t start = datadir_len;
for (; IS_DIR_SEPARATOR (file[start]); ++start)
;
- relocated_path = (std::string (gdb_datadir) + SLASH_STRING
- + file.substr (start));
+ relocated_path = gdb_datadir + SLASH_STRING + file.substr (start);
}
else
{
@@ -549,9 +548,8 @@ captured_main_1 (struct captured_main_args *context)
= xstrdup (relocate_gdb_directory (DEBUGDIR,
DEBUGDIR_RELOCATABLE).c_str ());
- gdb_datadir
- = xstrdup (relocate_gdb_directory (GDB_DATADIR,
- GDB_DATADIR_RELOCATABLE).c_str ());
+ gdb_datadir = relocate_gdb_directory (GDB_DATADIR,
+ GDB_DATADIR_RELOCATABLE);
#ifdef WITH_PYTHON_PATH
{
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-01 6:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01 6:57 [binutils-gdb] Fix leak due to assigning a xstrdup-ed string to the std::string gdb_datadir 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).