From patchwork Wed Jul 25 15:07:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 949224 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-482345-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fTOrIy6I"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41bHWD1tBMz9rxx for ; Thu, 26 Jul 2018 00:22:48 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=OeKK7KjBLsD1 C5Na/ACMGPLBJdbdrwszSKm2pXiQ80aYj0NlLTtJ2pOO/CPpckfFbJt51ZknpI9e JnZDYt87GThYqriv4vhjGW1dhzTxZUdcooxizj94fNu4o5+95ZYb67Lfgdrcr8kV +myELK7g+XhIMy6H7y63U1pCm7SYCYc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=sMZzGV0PbmVshCdC6c vBM7sFcSw=; b=fTOrIy6IjZteJ5tsRcO9FBNTG7GtpJqnXjc+6zUdr3qrV8Au3z R3T56A5QcspezD5jWvdx9fZq1D6ZUwlJOvCf5zDcTItdwyhTovMLg3TKRWyZnaQy +4wBL1xd1nZx+/mEu8H1nJDrxs6yFfXZMrjjCBggQ8H6eyJ+ywyariW7M= Received: (qmail 104086 invoked by alias); 25 Jul 2018 14:22:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 104073 invoked by uid 89); 25 Jul 2018 14:22:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=mainc, toplev, char**, UD:main.c X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 25 Jul 2018 14:22:39 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D00D3001FA0 for ; Wed, 25 Jul 2018 14:22:38 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-35.phx2.redhat.com [10.3.112.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8045F5D9CD; Wed, 25 Jul 2018 14:22:37 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] optinfo-emit-json.cc: fix trivial memory leak Date: Wed, 25 Jul 2018 11:07:28 -0400 Message-Id: <1532531248-25116-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes There's a small leak in class optrecord_json_writer, which shows up as a new leak in "make selftest-valgrind" as: ==50133== 40 bytes in 1 blocks are definitely lost in loss record 27 of 672 ==50133== at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==50133== by 0x1EF5CAF: xrealloc (xmalloc.c:177) ==50133== by 0xEDDA56: void va_heap::reserve(vec*&, unsigned int, bool) (vec.h:288) ==50133== by 0xEDD74D: vec::reserve(unsigned int, bool) (vec.h:1621) ==50133== by 0xEDD515: vec::safe_push(json::array* const&) (vec.h:1730) ==50133== by 0xEDB060: optrecord_json_writer::optrecord_json_writer() (optinfo-emit-json.cc:124) ==50133== by 0xEDD141: selftest::test_building_json_from_dump_calls() (optinfo-emit-json.cc:935) ==50133== by 0xEDD3AF: selftest::optinfo_emit_json_cc_tests() (optinfo-emit-json.cc:955) ==50133== by 0x1DEB3AA: selftest::run_tests() (selftest-run-tests.c:78) ==50133== by 0x1065264: toplev::run_self_tests() (toplev.c:2225) ==50133== by 0x1065486: toplev::main(int, char**) (toplev.c:2303) ==50133== by 0x1E4A092: main (main.c:39) The fix is trivial. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu; manually checked "make selftest-valgrind" (which with this fix is now back from four leaks down to three). Committed to trunk as r262967 (under the "obvious" rule). gcc/ChangeLog: * optinfo-emit-json.cc (class optrecord_json_writer): Convert field "m_scopes" from vec to auto_vec. --- gcc/optinfo-emit-json.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/optinfo-emit-json.cc b/gcc/optinfo-emit-json.cc index 6460a81..2199d52 100644 --- a/gcc/optinfo-emit-json.cc +++ b/gcc/optinfo-emit-json.cc @@ -75,7 +75,7 @@ private: json::array *m_root_tuple; /* The currently open scopes, for expressing nested optimization records. */ - vec m_scopes; + auto_vec m_scopes; }; /* optrecord_json_writer's ctor. Populate the top-level parts of the