From patchwork Sun Oct 21 14:04:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 987314 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-487972-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="bWJHRehA"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="r3ApN+uD"; 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 42dLy864nMz9sCQ for ; Mon, 22 Oct 2018 01:05:02 +1100 (AEDT) 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:mime-version :content-transfer-encoding; q=dns; s=default; b=GfFDrEZLhGiY7J5Q SVHdTQ1Ga7XedI7fjkAy8Su/maQxp90RZz1xCX84VKxsfVN2XgszHICkZa/Zv6sh Gvenr981Pj8YbgZ5aDS08hzCJwMvfxplypaOB5mvi6ltXgqd7KZWanhscP7oeDwJ +fKNS506YBE2zfXKtDJ2u+2VWOw= 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:mime-version :content-transfer-encoding; s=default; bh=77KIPUXzXFLoQvQ6Ev71G5 kBFYU=; b=bWJHRehAJhY8tE4qIlYqNFJR9R9z0cH3aWbFEeAcKQixjh+BtLh+8D v9CVJCghnGYZdcSN462LWtMpeoL66/La6MuKlUHNyQV9PRgFyuHmqu9AJOXmOyov wDjRnkIsrLTd1spVm8k59ySugGYLCONXZ9SkV6dsDaCH4ESrOgrp4= Received: (qmail 75546 invoked by alias); 21 Oct 2018 14:04:51 -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 75526 invoked by uid 89); 21 Oct 2018 14:04:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=installing, HContent-Transfer-Encoding:8bit X-HELO: mail-wr1-f47.google.com Received: from mail-wr1-f47.google.com (HELO mail-wr1-f47.google.com) (209.85.221.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 21 Oct 2018 14:04:49 +0000 Received: by mail-wr1-f47.google.com with SMTP id s18-v6so300650wrw.6; Sun, 21 Oct 2018 07:04:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=s3cXMtuwVp7w3LJFQHe3yRKHMXzXrjX8YSC41R9lrzg=; b=r3ApN+uDMmmPIl7PLf4v6v8zzCTtjrclI9DqGTJA9IKdvTJNrxmzlZW3Q9yGbUA6xg OB16p8RUtooqneuQNazTfrdAN5Bcyz0e+KeEuW5u3pqCKevoSAB3ffL17lCZIORtxd0s YAV8eYynM0ljFKNhJjYmHQdp8gc8Shbpeh3Wz/Ci/vjW92Ji4j1LmoI1vPxRXAPqBnVH X4ZZv145UYQFEEQsS2DT1W+K3mr1qQX3yhhQ7Gfytmc8zPhIzXJmHFSAHIvlpCM+pcoU ncx1usHIu0mtE5DM9kxLOJT2g2BNYJ70MF6a5UnXKJUGKBzxP3987KVPD4TDkXo1R2Iw w0TA== Received: from nbbrfq.loc (91-119-96-225.dsl.dynamic.surfer.at. [91.119.96.225]) by smtp.gmail.com with ESMTPSA id u76-v6sm20241349wmd.10.2018.10.21.07.04.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Oct 2018 07:04:45 -0700 (PDT) Received: from b by nbbrfq.loc with local (Exim 4.91) (envelope-from ) id 1gEELT-000810-7b; Sun, 21 Oct 2018 16:04:43 +0200 From: Bernhard Reutner-Fischer To: fortran@gcc.gnu.org Cc: Bernhard Reutner-Fischer , gcc-patches@gcc.gnu.org Subject: [PATCH,FORTRAN] Fix memory leak of gsymbol Date: Sun, 21 Oct 2018 16:04:34 +0200 Message-Id: <20181021140434.30743-1-rep.dot.nop@gmail.com> MIME-Version: 1.0 X-IsSubscribed: yes Hi! Regtested on x86_64-unknown-linux, installing on aldot/fortran-fe-stringpool. We did not free global symbols. For a simplified abstract_type_3.f03 valgrind reports: 96 bytes in 1 blocks are still reachable in loss record 461 of 602 at 0x48377D5: calloc (vg_replace_malloc.c:711) by 0x21257C3: xcalloc (xmalloc.c:162) by 0x98611B: gfc_get_gsymbol(char const*) (symbol.c:4341) by 0x932C58: parse_module() (parse.c:5912) by 0x9336F8: gfc_parse_file() (parse.c:6236) by 0x991449: gfc_be_parse_file() (f95-lang.c:204) by 0x11D8EDE: compile_file() (toplev.c:455) by 0x11DB9C3: do_compile() (toplev.c:2170) by 0x11DBCAF: toplev::main(int, char**) (toplev.c:2305) by 0x2045D37: main (main.c:39) This patch reduces leaks to LEAK SUMMARY: definitely lost: 344 bytes in 1 blocks indirectly lost: 3,024 bytes in 4 blocks possibly lost: 0 bytes in 0 blocks - still reachable: 1,576,174 bytes in 2,277 blocks + still reachable: 1,576,078 bytes in 2,276 blocks suppressed: 0 bytes in 0 blocks gcc/fortran/ChangeLog: 2018-10-21 Bernhard Reutner-Fischer * parse.c (clean_up_modules): Free gsym. --- gcc/fortran/parse.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c index b7265c42f58..f7c369a17ac 100644 --- a/gcc/fortran/parse.c +++ b/gcc/fortran/parse.c @@ -6066,7 +6066,7 @@ resolve_all_program_units (gfc_namespace *gfc_global_ns_list) static void -clean_up_modules (gfc_gsymbol *gsym) +clean_up_modules (gfc_gsymbol *&gsym) { if (gsym == NULL) return; @@ -6074,14 +6074,18 @@ clean_up_modules (gfc_gsymbol *gsym) clean_up_modules (gsym->left); clean_up_modules (gsym->right); - if (gsym->type != GSYM_MODULE || !gsym->ns) + if (gsym->type != GSYM_MODULE) return; - gfc_current_ns = gsym->ns; - gfc_derived_types = gfc_current_ns->derived_types; - gfc_done_2 (); - gsym->ns = NULL; - return; + if (gsym->ns) + { + gfc_current_ns = gsym->ns; + gfc_derived_types = gfc_current_ns->derived_types; + gfc_done_2 (); + gsym->ns = NULL; + } + free (gsym); + gsym = NULL; }