From patchwork Sun Sep 29 16:39:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 34713 Received: (qmail 129468 invoked by alias); 29 Sep 2019 16:39:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 129459 invoked by uid 89); 29 Sep 2019 16:39:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: mailsec112.isp.belgacom.be Received: from mailsec112.isp.belgacom.be (HELO mailsec112.isp.belgacom.be) (195.238.20.108) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 29 Sep 2019 16:39:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1569775152; x=1601311152; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=SiejAOnXFsra9XNPpqsGaaBGJsqfQbwyTYu2Axc1M5E=; b=0NxA47YY7RtcLdWCfUQjLLp69+NVY1fmUiNoZs5GFUbNwkuJqig+tG1K PKVy6b1ruE7lna/vO/KlfWbw4C0eKA==; Received: from 255.38-242-81.adsl-dyn.isp.belgacom.be (HELO md.home) ([81.242.38.255]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 29 Sep 2019 18:39:10 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix leak due to assigning a xstrdup-ed string to the std::string gdb_datadir Date: Sun, 29 Sep 2019 18:39:03 +0200 Message-Id: <20190929163903.21699-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes 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. Also removes a useless conversion of gdb_datadir to std::string. gdb/ChangeLog YYYY-MM-DD Philippe Waroquiers * 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. --- gdb/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gdb/main.c b/gdb/main.c index 7fab8ff8da..4ebb2127fe 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 { @@ -550,8 +549,8 @@ captured_main_1 (struct captured_main_args *context) DEBUGDIR_RELOCATABLE).c_str ()); gdb_datadir - = xstrdup (relocate_gdb_directory (GDB_DATADIR, - GDB_DATADIR_RELOCATABLE).c_str ()); + = relocate_gdb_directory (GDB_DATADIR, + GDB_DATADIR_RELOCATABLE).c_str (); #ifdef WITH_PYTHON_PATH {