From patchwork Fri Nov 5 21:17:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 47138 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CBD96385840A for ; Fri, 5 Nov 2021 21:18:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBD96385840A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636147105; bh=QScYhx/boP7kQbYpgjFdWYdOudNBT4xsExa1piisXJA=; 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=XhqcHDe0ONtyVBzQMvHjGX1piXo9a/xHGniM3tZn1KqU2KOQazdISxq5dwmCVY/Su rIchW8Nzfp2aw9djL8akRkBD7V63Kyg6fdleG1fI/+5L9Mlj0H77WBH3wjfOGEVodp alrbXd11HPtbvT+CQ/yw39qIMe6bXd3MWZ5S5pgE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 25061385841A; Fri, 5 Nov 2021 21:17:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 25061385841A Received: by mail-wm1-x335.google.com with SMTP id z11-20020a1c7e0b000000b0030db7b70b6bso10484158wmc.1; Fri, 05 Nov 2021 14:17:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QScYhx/boP7kQbYpgjFdWYdOudNBT4xsExa1piisXJA=; b=fkhbWwaScRW/XaT+OjVy5thymFExVLLT7aojsAoqqX1L45/m3xo6SnzqBI23qmjO/j xWsbSuhUqmyx5Xyo6dVdHL/jtWhRM7HyiAmy7WKTTdWYkJ7MMEx9+QHdN0laKxcKM5v9 p/ZBGAIvLzwDa3PVOcQ1gR7A+grA8SHVX1fkiO9jf99ac5Iu9VO9d6vQBFw2vLGdJFK6 DemKSP54CvJqum6jRx+XU5kAoLBkt+1dL4OT5L3nJjlYvwQ2HxrhxJtMBxxJxf+bDSUx wIrYvCmUcHuvyUqVXXUjt70Wr/PHlqNYXAkwhm1+ngI1BvqH8ORfvQtlsEEczWpibCeT Znkg== X-Gm-Message-State: AOAM532z4lHI+vKInNzXtIEzsgLPqeKDqCTCJumNh5ASShGBrm0DZahf lPpjNLkwkdpxDXgQrDFHaCk= X-Google-Smtp-Source: ABdhPJxko1Zgv/JiQL3Kj/EGZ5L7F4XrD/Ae2J0kW8yiKhQhAm1SYTQbYgjj4XbN8hDXhwQjH/dp+w== X-Received: by 2002:a1c:2507:: with SMTP id l7mr33107984wml.186.1636147059065; Fri, 05 Nov 2021 14:17:39 -0700 (PDT) Received: from nbbrfq.weghof (dynamic-2bq7di4u2lfl4qjka9-pd01.res.v6.highway.a1.net. [2001:871:227:33a8:f6a3:c58c:7641:e771]) by smtp.gmail.com with ESMTPSA id t8sm8700333wrv.30.2021.11.05.14.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Nov 2021 14:17:38 -0700 (PDT) Received: from b by nbbrfq.weghof with local (Exim 4.95) (envelope-from ) id 1mj6af-009UND-K3; Fri, 05 Nov 2021 22:17:37 +0100 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 1/2] Add free_cpp_dirs() Date: Fri, 5 Nov 2021 22:17:17 +0100 Message-Id: <20211105211718.2261686-2-rep.dot.nop@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211105211718.2261686-1-rep.dot.nop@gmail.com> References: <20211105211718.2261686-1-rep.dot.nop@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer Cc: Bernhard Reutner-Fischer , Bernhard Reutner-Fischer Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Bernhard Reutner-Fischer gcc/ChangeLog: * incpath.c (free_cpp_dirs): New function. * incpath.h (free_cpp_dirs): Ditto. --- This adds a helper to allow the fortran FE to free it's include dirs. Bootstrapped and regtested without new regressions on x86_64-unknown-linux. Ok for trunk? --- gcc/incpath.c | 13 +++++++++++++ gcc/incpath.h | 1 + 2 files changed, 14 insertions(+) diff --git a/gcc/incpath.c b/gcc/incpath.c index 52dbb806b1b..de77a56062c 100644 --- a/gcc/incpath.c +++ b/gcc/incpath.c @@ -513,6 +513,19 @@ get_added_cpp_dirs (incpath_kind chain) return heads[chain]; } +/* Free all cpp dirs. */ +void +free_cpp_dirs (void) +{ + struct cpp_dir **pcur, *cur; + for (pcur = &heads[INC_QUOTE]; *pcur;) + { + cur = *pcur; + *pcur = cur->next; + free_path (cur, REASON_QUIET); + } +} + #if !(defined TARGET_EXTRA_INCLUDES) || !(defined TARGET_EXTRA_PRE_INCLUDES) static void hook_void_charptr_charptr_int (const char *sysroot ATTRIBUTE_UNUSED, const char *iprefix ATTRIBUTE_UNUSED, diff --git a/gcc/incpath.h b/gcc/incpath.h index 2a4a314d7f9..4bf878b4e74 100644 --- a/gcc/incpath.h +++ b/gcc/incpath.h @@ -34,6 +34,7 @@ extern void register_include_chains (cpp_reader *, const char *, int, int, int); extern void add_cpp_dir_path (struct cpp_dir *, incpath_kind); extern struct cpp_dir *get_added_cpp_dirs (incpath_kind); +extern void free_cpp_dirs(void); struct target_c_incpath_s { /* Do extra includes processing. STDINC is false iff -nostdinc was given. */ From patchwork Fri Nov 5 21:17:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 47139 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13F3F3858428 for ; Fri, 5 Nov 2021 21:19:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13F3F3858428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636147163; bh=Nqpm+uXGcNKoc4iNlVnfiOzzzR+mGYJZV9jEl4ETi1Q=; 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=kbyPV73Htqmor2hgAQ9QTDWz2y00y49M3ikbqE9/7LmBMZliS+RIlp2aGAgRZUoJs YwQKVY6HOS2P0OxyU89xAdfDRFiZLupzhOtKpkK8WziusACkdnGZXGP/M8v8h5fom5 Hu3abL0JO8JoHbYouos3FgPI8mhQG3px3Mz1RPb8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 E663C385840A; Fri, 5 Nov 2021 21:17:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E663C385840A Received: by mail-wr1-x42d.google.com with SMTP id u1so15707423wru.13; Fri, 05 Nov 2021 14:17:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Nqpm+uXGcNKoc4iNlVnfiOzzzR+mGYJZV9jEl4ETi1Q=; b=FKMbklvshCk7W+ePRnAAEmxGCCbyqKuov4oeirPbfxdTSjiw4AgEU3goEA+7EXVreb NzWharfyeb9e5Tfdz4YtnxiKI3IL/5r3wiGOjctC9UpaDn3EM7EmeNw9MiVm8vql3SDm dQw+HSn28BNufLPD0u7HTSxG6/KxIzD94j1/bBmFHtLa+VCsmYyzDdkbqpoyz6kJwfEt S/0WWXqTypCb7Gwm3ZKY6PsVcaXZx0Hzp0OJ1ROh/QsPKlVKqI6TrKnYMGJJJp+SPr0M hSL5KWMWNl3rjQM5L+TlCS4LOE0bPJIT8YX2wgEVW8VbZk6zF+3AuDd3hRhzJRss8VmB Ri/g== X-Gm-Message-State: AOAM532Y4kILXUDiZ78PDJYCFmGshPgoxBu3f6f8tXTK4a0j4+BhoGnO ct0ek6QnaulGjcujn3zGJ2qd6HqWqiM= X-Google-Smtp-Source: ABdhPJzTtRe1n5KGz6V7xjEDpL6r/fANyyhrwFFCAOoYUS2TWq4iYCl5UBrYy7UxKCRtWubk8wfFlg== X-Received: by 2002:a05:6000:1813:: with SMTP id m19mr67199679wrh.51.1636147058794; Fri, 05 Nov 2021 14:17:38 -0700 (PDT) Received: from nbbrfq.weghof (dynamic-2bq7di4u2lfl4qjka9-pd01.res.v6.highway.a1.net. [2001:871:227:33a8:f6a3:c58c:7641:e771]) by smtp.gmail.com with ESMTPSA id p27sm8300557wmi.28.2021.11.05.14.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Nov 2021 14:17:38 -0700 (PDT) Received: from b by nbbrfq.weghof with local (Exim 4.95) (envelope-from ) id 1mj6af-009UNG-KP; Fri, 05 Nov 2021 22:17:37 +0100 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 2/2] Fortran: Fix memory leak in gfc_add_include_path [PR68800] Date: Fri, 5 Nov 2021 22:17:18 +0100 Message-Id: <20211105211718.2261686-3-rep.dot.nop@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211105211718.2261686-1-rep.dot.nop@gmail.com> References: <20211105211718.2261686-1-rep.dot.nop@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.1 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer Cc: Bernhard Reutner-Fischer , Bernhard Reutner-Fischer Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Bernhard Reutner-Fischer gcc/fortran/ChangeLog: PR fortran/68800 * cpp.h (gfc_cpp_free_cpp_dirs): New declaration. * cpp.c (gfc_cpp_free_cpp_dirs): New definition. (gfc_cpp_add_include_path, gfc_cpp_add_include_path_after): Add comment. * f95-lang.c (gfc_finish): Call gfc_cpp_free_cpp_dirs. * scanner.c (add_path_to_list): Allocate unzeroed memory. (gfc_add_include_path): Add comment and fix formatting. --- Bootstrapped and regtested without regressions on x86_64-unknown-linux. Ok for trunk? Note: in add_path_to_list i changed dir->path = XCNEWVEC to XNEWVEC since strcpy and strcat add a terminating null byte for us anyway. Fixes: -== 68 bytes in 1 blocks are still reachable in loss record 228 of 371 -== at : malloc (vg_replace_malloc.c:380) -== by : xmalloc (xmalloc.c:149) -== by : xstrdup (xstrdup.c:34) -== by : gfc_add_include_path(char const*, bool, bool, bool, bool) (scanner.c :428) -== by : gfc_handle_option(unsigned long, char const*, long, int, unsigned in t, cl_option_handlers const*) (options.c:702) -== by : handle_option(gcc_options*, gcc_options*, cl_decoded_option const*, unsigned int, int, unsigned int, cl_option_handlers const*, bool, diagnostic_con text*) (opts-common.c:1181) -== by : read_cmdline_option(gcc_options*, gcc_options*, cl_decoded_option*, unsigned int, unsigned int, cl_option_handlers const*, diagnostic_context*) (opt s-common.c:1431) -== by : read_cmdline_options (opts-global.c:237) -== by : decode_options(gcc_options*, gcc_options*, cl_decoded_option*, unsig ned int, unsigned int, diagnostic_context*, void (*)()) (opts-global.c:319) -== by : toplev::main(int, char**) (toplev.c:2273) -== by : main (main.c:39) --- gcc/fortran/cpp.c | 13 +++++++++++-- gcc/fortran/cpp.h | 1 + gcc/fortran/f95-lang.c | 2 +- gcc/fortran/scanner.c | 7 ++++--- 4 files changed, 17 insertions(+), 6 deletions(-) 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); } -/* PATH must be malloc-ed and NULL-terminated. */ +/* Free all cpp include dirs. */ +void +gfc_cpp_free_cpp_dirs (void) +{ + free_cpp_dirs (); +} + +/* PATH must be NULL-terminated. */ void gfc_cpp_add_include_path (char *path, bool user_supplied) { /* CHAIN sets cpp_dir->sysp which differs from 0 if PATH is a system - include path. Fortran does not define any system include paths. */ + include path. Fortran does not define any system include paths. + incpath.c manages the incoming, xstrdup()ed path. */ int cxx_aware = 0; add_path (path, INC_BRACKET, cxx_aware, user_supplied); @@ -742,6 +750,7 @@ gfc_cpp_add_include_path (char *path, bool user_supplied) void gfc_cpp_add_include_path_after (char *path, bool user_supplied) { + /* incpath.c manages the incoming, xstrdup()ed path. */ int cxx_aware = 0; add_path (path, INC_AFTER, cxx_aware, user_supplied); } 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; + gfc_cpp_free_cpp_dirs (); } /* These functions and variables deal with binding contours. We only diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index 69b81ab97f8..268d1e3e7fb 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -370,7 +370,7 @@ add_path_to_list (gfc_directorylist **list, const char *path, char *q; size_t len; int i; - + p = path; while (*p == ' ' || *p == '\t') /* someone might do "-I include" */ if (*p++ == '\0') @@ -409,7 +409,7 @@ add_path_to_list (gfc_directorylist **list, const char *path, *list = dir; dir->use_for_modules = use_for_modules; dir->warn = warn; - dir->path = XCNEWVEC (char, strlen (p) + 2); + dir->path = XNEWVEC (char, strlen (p) + 2); strcpy (dir->path, p); strcat (dir->path, "/"); /* make '/' last character */ } @@ -424,8 +424,9 @@ gfc_add_include_path (const char *path, bool use_for_modules, bool file_dir, defer_warn); /* For '#include "..."' these directories are automatically searched. */ + /* CPP manages 'path' on it's own via incpath.c so give it it's own copy. */ if (!file_dir) - gfc_cpp_add_include_path (xstrdup(path), true); + gfc_cpp_add_include_path (xstrdup (path), true); }