From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 2B8EA3858401; Sun, 7 Nov 2021 01:38:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2B8EA3858401 Received: by mail-wr1-x42d.google.com with SMTP id t30so20133530wra.10; Sat, 06 Nov 2021 18:38:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O6AFBIwythn5ZzxefqC6m59hgiyh3mJniOaEAeF92Pg=; b=K2ljA0Dxc26nfwg+Fy8Ytt5/zEq5HrDCts3NYB88gap9IiKpo57IRRE4P10ZplbHb1 dOmVKsRAShZN7RFThaHT+8Wk/iNNGMqi8kIabMrTrFEWcOUGJNaFRciT75soR2w9Nfxx jTUHa5b5tixlFidUuwZPgX4RffuSlQX3ramH16RcgJ4X3tkUUWu5GiI6FX2c8zbyIZDQ zPgemiS0/LisG8+vc5WAyJVP27yVxNnIkBiNPWpLgIaUyp3zYv8IJflQhErE9edOzOLN dRj0cfvio+HIBaMt2YE3spkh+8kl2ZzONpjOIQdFwdM1WgJIl2R94iAFYeW3RmVsIEp9 Ti/A== X-Gm-Message-State: AOAM533f5sGLAIFiY02CFjeAA1E6bFbR1Dh/ecbEnzzxZIjeug0YXltK EXrNpS3QCZPGUowtZHY1hjU= X-Google-Smtp-Source: ABdhPJwRVOh/ZUrq/FBgM5VUUqHPWhLoC+QMJUtFVkEO3AGRbrz1a8RdnBJOVjjnxWOXvHT03Na00Q== X-Received: by 2002:a05:6000:1548:: with SMTP id 8mr53541559wry.279.1636249105177; Sat, 06 Nov 2021 18:38:25 -0700 (PDT) Received: from nbbrfq (dynamic-2bq7di4u2lfl4qjka9-pd01.res.v6.highway.a1.net. [2001:871:227:33a8:f6a3:c58c:7641:e771]) by smtp.gmail.com with ESMTPSA id n7sm11955072wro.68.2021.11.06.18.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 18:38:24 -0700 (PDT) Date: Sun, 7 Nov 2021 02:38:21 +0100 From: Bernhard Reutner-Fischer To: Harald Anlauf Cc: rep.dot.nop@gmail.com, gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org, Bernhard Reutner-Fischer Subject: Re: [PATCH 2/2] Fortran: Fix memory leak in gfc_add_include_path [PR68800] Message-ID: <20211107023821.34234999@nbbrfq> In-Reply-To: References: <20211105211718.2261686-1-rep.dot.nop@gmail.com> <20211105211718.2261686-3-rep.dot.nop@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Nov 2021 01:38:30 -0000 On Sat, 6 Nov 2021 20:22:53 +0100 Harald Anlauf wrote: > Hi Bernhard, > > I cannot comment on the gcc/ parts, but > > > diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c > > index e86386c8b17..04fe8fe460b 100644 > > --- a/gcc/fortran/cpp.c > > +++ b/gcc/fortran/cpp.c > > @@ -728,12 +728,20 @@ gfc_cpp_done (void) > > cpp_clear_file_cache (cpp_in); > > } > > why do you introduce a wrapper for something outside of fortran > that is used only once, > > > -/* PATH must be malloc-ed and NULL-terminated. */ > > +/* Free all cpp include dirs. */ > > +void > > +gfc_cpp_free_cpp_dirs (void) > > +{ > > + free_cpp_dirs (); > > +} > > diff --git a/gcc/fortran/cpp.h b/gcc/fortran/cpp.h > > index 44644a2a333..963b9a9c89e 100644 > > --- a/gcc/fortran/cpp.h > > +++ b/gcc/fortran/cpp.h > > @@ -46,6 +46,7 @@ void gfc_cpp_post_options (bool); > > bool gfc_cpp_preprocess (const char *source_file); > > > > void gfc_cpp_done (void); > > +void gfc_cpp_free_cpp_dirs (void); > > > > void gfc_cpp_add_include_path (char *path, bool user_supplied); > > void gfc_cpp_add_include_path_after (char *path, bool user_supplied); > > diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c > > index 58dcaf01d75..ec4c2cf01d9 100644 > > --- a/gcc/fortran/f95-lang.c > > +++ b/gcc/fortran/f95-lang.c > > @@ -275,7 +275,7 @@ gfc_finish (void) > > gfc_cpp_done (); > > gfc_done_1 (); > > gfc_release_include_path (); > > - return; > > namely here? > > > + gfc_cpp_free_cpp_dirs (); > > } > > Why not call free_cpp_dirs () here directly, omit all unnecessary > stuff, and maybe only add a brief comment here? cpp.c includes incpath.h, f95-lang.c does not and should not. So the cleanest thing is to keep the cpp handling in cpp.[ch] and have the language frontend call into it's cpp bits. It would be rather rogue to extern void free_cpp_dirs (void); in f95-lang.c and directly call it in gfc_finish, i'd say? thanks,