From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailsec211.isp.belgacom.be (mailsec211.isp.belgacom.be [195.238.22.107]) by sourceware.org (Postfix) with ESMTPS id 5866F3858D3C for ; Sun, 27 Nov 2022 18:25:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5866F3858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=skynet.be Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=skynet.be DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=rmail; t=1669573516; x=1701109516; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=jty6OIstIwCUlv6Z9+LWlnpDbNHvxbyaBovgwnPsh18=; b=dZ+4IXKI7lF9+4FOVt5ocBXOqnPu8S5o4xAOXuORA9KKLi62GLu/X1Gy xIulDRpkrk0bdZUJF9sHWjpkmkG6r5AkwE56TrQ3zvOLcKFECtwvTDqVk u43RgG1vwqsFw4Y/UyMuYULw5oABX9oPtxG/89XiGJqmqh4+OZuuOK1ed U=; X-ExtLoop: 1 X-IPAS-Result: =?us-ascii?q?A2AwBABUqoNj/1uGgG1aHgEBCxIMSYE7C4MxgVinSotWg?= =?us-ascii?q?X4PAQEBAQEBAQEBCTETBAEBhQWFCiY2Bw4BAgQBAQEBAwIDAQEBAQEBAwEBB?= =?us-ascii?q?gEBAQEBAQYEAYEchS85DYI1IoN/KwsBRiiEJgGDIq8HMxoCZYRwmmaBZ4FAi?= =?us-ascii?q?1SFQjeBVUSECIYGhXEEmRQDCQMHBUlAAwsYDRYyChMyG1gOCR8cJQ0FBhIDI?= =?us-ascii?q?GwFBzoPKC9kKxwbB4EMKigVAwQEAwIGEwMiAg0pMRQEKRMNKydvCQIDImoDA?= =?us-ascii?q?wQoLAMJIR8HJyQ8B1Y6BQMCDyA4BgMJAwIiVHIvEhQFAwsVJQgFSwQIOQUGU?= =?us-ascii?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OSae+8osBcTsqjsMiBIKoaSvp037BZ7TEUdfU1SL36qy nAppomPHPP4wr5HUtNpTniAsm9qBHnlKKdiLN5VYtKHjOKhILCFu5fBP7Zsljd8kPFnNK1rZ 0QEZRDNA== X-IronPort-Anti-Spam-Filtered: true Received: from unknown (HELO md.home) ([109.128.134.91]) by relay.proximus.be with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2022 19:25:14 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] fix leak in gdb_environ Date: Sun, 27 Nov 2022 19:25:04 +0100 Message-Id: <20221127182504.867308-1-philippe.waroquiers@skynet.be> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: valgrind reports a leak when assigning a gdb_environ to another gdb_environ. The memory allocated for the target gdb_environ env variables is not released. The gdb_environ selftest reproduces the leak (see below). Fix the leak by clearing the target gbd_environ before std::move-ing the members. Tested natively and re-running all tests under valgrind. ==3261873== 4,842 bytes in 69 blocks are definitely lost in loss record 6,772 of 6,839 ==3261873== at 0x483979B: malloc (vg_replace_malloc.c:393) ==3261873== by 0x25A454: xmalloc (alloc.c:57) ==3261873== by 0x7D1E4E: xstrdup (xstrdup.c:34) ==3261873== by 0x7E2A51: gdb_environ::from_host_environ() (environ.cc:56) ==3261873== by 0x66F1C8: test_reinit_from_host_environ (environ-selftests.c:78) ==3261873== by 0x66F1C8: selftests::gdb_environ_tests::run_tests() (environ-selftests.c:285) ==3261873== by 0x7EFC43: operator() (std_function.h:622) = --- gdbsupport/environ.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gdbsupport/environ.cc b/gdbsupport/environ.cc index f5f6b38e19c..2d8e3ea6e92 100644 --- a/gdbsupport/environ.cc +++ b/gdbsupport/environ.cc @@ -29,6 +29,8 @@ gdb_environ::operator= (gdb_environ &&e) if (&e == this) return *this; + this->clear (); + m_environ_vector = std::move (e.m_environ_vector); m_user_set_env = std::move (e.m_user_set_env); m_user_unset_env = std::move (e.m_user_unset_env); -- 2.30.2