From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yMA7DpJ3emIidAUAWB0awg (envelope-from ) for ; Tue, 10 May 2022 10:32:50 -0400 Received: by simark.ca (Postfix, from userid 112) id 349E71E21F; Tue, 10 May 2022 10:32:50 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=X3M4pRCB; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BCBF51E01D for ; Tue, 10 May 2022 10:32:49 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DD8E395447B for ; Tue, 10 May 2022 14:32:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DD8E395447B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1652193169; bh=bVqaizi/593Maq+T5IfmGPPiEIfOEMtbNX/ffH/sLU8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=X3M4pRCBnMQa+2RUJVegCj6rDSovjSjIQpLI0yccz8nYRHU0a9HgZzkok9H28k6EI KB5piOfsMX0gKNOTCEn7zq7+WMplXHp/qGc5VmIdoVzdPdcmstoHx7bgAiqbiNr2oS DngIk9oR4xj5AZrVHAOHsVS8LqHcLGYFAExUsf/E= Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by sourceware.org (Postfix) with ESMTPS id 14B403954402 for ; Tue, 10 May 2022 14:25:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 14B403954402 X-IronPort-AV: E=McAfee;i="6400,9594,10342"; a="251436085" X-IronPort-AV: E=Sophos;i="5.91,214,1647327600"; d="scan'208";a="251436085" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2022 07:25:58 -0700 X-IronPort-AV: E=Sophos;i="5.91,214,1647327600"; d="scan'208";a="565665352" Received: from labpcdell3650-003.iul.intel.com (HELO localhost) ([172.28.49.87]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2022 07:25:57 -0700 To: gdb-patches@sourceware.org Subject: [PATCH 16/18] gdb, testsuite, fortran: fix double free in mixed-lang-stack.exp Date: Tue, 10 May 2022 16:24:35 +0200 Message-Id: <20220510142437.1397399-17-nils-christian.kempke@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220510142437.1397399-1-nils-christian.kempke@intel.com> References: <20220510142437.1397399-1-nils-christian.kempke@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Nils-Christian Kempke via Gdb-patches Reply-To: Nils-Christian Kempke Cc: JiniSusan.George@amd.com, aburgess@redhat.com Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" While testing mixed-lang-stack I realized that valgrind actually complained about a double free in the test. All done ==2503051== ==2503051== HEAP SUMMARY: ==2503051== in use at exit: 0 bytes in 0 blocks ==2503051== total heap usage: 26 allocs, 27 frees, 87,343 bytes allocated ==2503051== ==2503051== All heap blocks were freed -- no leaks are possible ==2503051== ==2503051== For lists of detected and suppressed errors, rerun with: -s ==2503051== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) Reason for this is that in mixed-lang-stack.cpp in mixed_func_1f an object "derived_type obj" goes on the stack which is then passed-by-value (so copied) to mixed_func_1g. The default copy-ctor will be called but, since derived_type contains a heap allocated string and the copy constructor is not implemented it will only be able to shallow copy the object. Right after each of the functions the object gets freed - on the other hand the d'tor of derived_type actually is implemented and calls free on the heap allocated string which leads to a double free. Instead of obeying the rule of 3/5 I just got rid of all that since it does not serve the test. The string is now just a const char* = ".." object member. --- gdb/testsuite/gdb.fortran/mixed-lang-stack.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/gdb/testsuite/gdb.fortran/mixed-lang-stack.cpp b/gdb/testsuite/gdb.fortran/mixed-lang-stack.cpp index 39ff6c201f..b5ae7dac0a 100644 --- a/gdb/testsuite/gdb.fortran/mixed-lang-stack.cpp +++ b/gdb/testsuite/gdb.fortran/mixed-lang-stack.cpp @@ -26,17 +26,7 @@ class base_one class base_two { public: - base_two () - { - string = strdup ("Something in C++"); - } - - ~base_two () - { - free (string); - } - - char *string = nullptr; + const char *string = "Something in C++"; float val = 3.5; }; -- 2.25.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928