From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id BE7E53858CDA for ; Mon, 22 Apr 2024 18:05:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE7E53858CDA Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BE7E53858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713809159; cv=none; b=EhPPM6E/oES0p26vTOlKxpGJIFJBBW+ov1/Lss3v3vaKNa/eIcCvTMwD2itGmJWV/YuAmeBiK58z0RUCvMuiVTWg+rkUoERCfaChv7Ft7zVQYoCQ19LHnAQjsNzs7TJsEBMxmTtOpeP7Mapl2We6NGoFNglKkWmYbH7N7EffLYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713809159; c=relaxed/simple; bh=EEIpT/vpSEmYTmdE570DEI/yRJkRaaZfaGL5KtABNeY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YIxWQ+fMK0qrMVTFqYssnO300WS/cYiRe1/INk1QAe8y3TnS45K2GWdxNJFI75M2sB7pigQvqAXe2QyetnU8zUn4asZVoyzw20FppyxPPnWNduGlwh1CiuyDGDwq4PFWBBt/Bs3CgSGrdofvjTfIYH3a6WFfbPKLG0cZVBEK3j8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-7d9c2096c29so233931339f.0 for ; Mon, 22 Apr 2024 11:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1713809149; x=1714413949; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Y6z5arMz5PpPGiX8lMWuoROIwMccHbgJyjoWhhuVZWc=; b=JXLC/JJ2m6YgITpk3C9c+q5JbWQTpYL0FYMEch/+Jh/z4kISfvVg2dcRX0lXQqxAZT GMw4gzom1tdSWIcP4pypFRD31kX/XCLHZ/Xh5nR4WV8HdH2z5LxzeuOVOm9bbJ6B4qiy pR6fD7uJujM1ubyY3Rr76fsLsCUcpfE/YSCGD4Pm991vY4nHDAdZm9f/DjWLvMtJ8u3K CIN/w686eJn4wOgjrW2YPKyGiL6L9x/l29CmAVMwmk+3vzoDBs29h+s/5WTjqAKAaV41 MtE2cfd9Uln2nkBouu/TrMR5dhuQ+emKdRnPnMcP96cidfteN8yIL5iRne4rhsx34pdF 6zAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713809149; x=1714413949; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Y6z5arMz5PpPGiX8lMWuoROIwMccHbgJyjoWhhuVZWc=; b=XzERSKGGuyiAlEEPh4g4N2JjFFad5SuhISDO+Z24gZarpTtLMuejEKxU7rYuilTaNe EyFldr1+ZntrEYfo3R+WG51lRWRmE9Y5coz54aoFEP8Re5XZzb5g1aXp7GuNMy1F5+1m CSsE+FRTApN2mm3+C4I7S/sbC1SvCk58vBLeZ9t1px7KFG2GugSBFh8mKP1ykVesB56O T4XOY6+4xFNZHhNE0oN6yE3Iem42M27g9/mIfNavdOlidT+K0s82lHFpp5HlECaXbFFJ 7jqv5zQotNRuQD20FZql63RfSfSqsMeVrqgDSluiHVAZGoZ5WgfUOe6OJzWY3cSInqsN ay/g== X-Gm-Message-State: AOJu0YxsS2+mUJ30Bk3rTGehyfXhvV+xU7+GFNgO9iitWMQB8Fwoh6G0 3NW/EYM2t7FnfhWKsdoyLeYhvnlESs/Tzms24XyGJUozxvrpSdGCUxjIRZHhsQe0MkgcgpKwh8I = X-Google-Smtp-Source: AGHT+IGprUf1HoCakfYgM1qup8vHscL+rmaK/qz8SWF7adk22cTpi2v9PlFuknocMCDSeOw6dts5NA== X-Received: by 2002:a5d:9645:0:b0:7d8:6adc:78f0 with SMTP id d5-20020a5d9645000000b007d86adc78f0mr13206774ios.7.1713809148794; Mon, 22 Apr 2024 11:05:48 -0700 (PDT) Received: from localhost.localdomain (97-122-86-252.hlrn.qwest.net. [97.122.86.252]) by smtp.gmail.com with ESMTPSA id a6-20020a056638164600b0047ec90db985sm3095359jat.102.2024.04.22.11.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 11:05:48 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix leak with internal functions Date: Mon, 22 Apr 2024 12:05:38 -0600 Message-ID: <20240422180538.3067094-1-tromey@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 reported a memory leak on exit with internal functions. To fix this, I added a new case to clear_internalvar, and then arranged to call clear_internalvar when an internalvar is deleted. Also, because an internalvar can reference a value, it seemed prudent to clear 'internalvars' from the final cleanup in value.c. Regression tested on x86-64 Fedora 38. I also did a bit of testing by hand with valgrind and ASAN. --- gdb/testsuite/gdb.base/gdbvars.exp | 8 ++++++++ gdb/value.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/gdb/testsuite/gdb.base/gdbvars.exp b/gdb/testsuite/gdb.base/gdbvars.exp index 7ec7df36b9e..32fd4c4da4e 100644 --- a/gdb/testsuite/gdb.base/gdbvars.exp +++ b/gdb/testsuite/gdb.base/gdbvars.exp @@ -102,6 +102,14 @@ proc test_convenience_functions {} { gdb_test "print \$_isvoid (foo_int ())" " = 0" \ "Check whether non-void function is void" + + gdb_test "print \$isvoid_copy = \$_isvoid" \ + " = " + gdb_test "print \$isvoid_copy = 0" " = 0" + + # Can't reset the canonical name. + gdb_test "print \$_isvoid = 0" \ + "Cannot overwrite convenience function _isvoid" } proc test_value_history {} { diff --git a/gdb/value.c b/gdb/value.c index 1bd180a62cc..58e4a975485 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1882,6 +1882,11 @@ struct internalvar : name (std::move (name)) {} + ~internalvar () + { + clear_internalvar (this); + } + std::string name; /* We support various different kinds of content of an internal variable. @@ -2319,6 +2324,14 @@ clear_internalvar (struct internalvar *var) xfree (var->u.string); break; + case INTERNALVAR_FUNCTION: + if (var->u.fn.canonical) + { + xfree (var->u.fn.function->name); + xfree (var->u.fn.function); + } + break; + default: break; } @@ -4513,5 +4526,6 @@ and exceeds this limit will cause an error."), add_final_cleanup ([] () { all_values.clear (); + internalvars.clear (); }); } -- 2.43.0