From: Costas Argyris <costas.argyris@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Jonathan Wakely <jwakely@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] driver: Fix memory leak.
Date: Thu, 7 Dec 2023 16:01:11 +0000 [thread overview]
Message-ID: <CAHyHGCmN3cx8Nf44Mafq1bM4Ab98FQriujpwAC_98Bvyug0_+w@mail.gmail.com> (raw)
In-Reply-To: <ZXHn9HhS7N5vMzVI@tucnak>
[-- Attachment #1.1: Type: text/plain, Size: 2019 bytes --]
Thanks for all the explanations.
In that case I restrict this patch to just freeing the buffer from
within driver::finalize only (I think it should be XDELETEVEC
instead of XDELETE, no?).
On Thu, 7 Dec 2023 at 15:42, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Dec 07, 2023 at 03:16:29PM +0000, Costas Argyris wrote:
> > > Still reachable memory at exit e.g. from valgrind is not a bug.
> >
> > Indeed, this is coming from a valgrind report here:
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93019
> >
> > where it was noted that the driver memory leaks could be
> > problematic for JIT.
>
> In the invoke_embedded_driver JIT case yes, that calls driver::finalize (),
> which is why it should be freed before clearing the pointer in there (as
> then it is a real leak).
>
> > So, since using std::vector did reduce the valgrind records
> > by one (I only targeted a single variable to begin with) I took
> > that as a good sign.
> >
> > Regarding adding a call to XDELETE (mdswitches), yes,
> > that would help in the case where driver::finalize () is actually
> > called, which I think is for JIT. I was trying to take care of the
> > case where it doesn't get called as well, but from what you say
> > I take it that this case is not of interest.
>
> That is wasted compile time on a non-issue.
>
> If you see a JIT issue with definitely lost records, that is something
> that obviously should be fixed (but even in that area I think we've been a
> little bit lazy in the option handling).
> The most important is that the actual compiler binaries (cc1, cc1plus, ...)
> don't leak memory (in the definitely lost kind) like crazy, we have
> --enable-checking=valgrind
> for that purpose, where the driver runs cc1/cc1plus etc. under valgrind,
> but this is very expensive and slow, so usually it is run once during a
> cycle (if at all), on a fast machine could take even in non-bootstrap mode
> a weekend to go through the whole testsuite, then one can look at the
> leaks.
>
> Jakub
>
>
[-- Attachment #2: 0001-driver-Fix-memory-leak-in-driver-finalize.patch --]
[-- Type: application/octet-stream, Size: 670 bytes --]
From 13f6ce5c164f1f0fded25f01b1d38f90b354fe13 Mon Sep 17 00:00:00 2001
From: Costas Argyris <costas.argyris@gmail.com>
Date: Thu, 7 Dec 2023 15:52:51 +0000
Subject: [PATCH] driver: Fix memory leak in driver::finalize ()
Free buffer before setting the pointer to NULL.
Signed-off-by: Costas Argyris <costas.argyris@gmail.com>
---
gcc/gcc.cc | 1 +
1 file changed, 1 insertion(+)
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 9f21ad9453e..bf4a02f76e7 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -11366,6 +11366,7 @@ driver::finalize ()
input_from_pipe = 0;
suffix_subst = NULL;
+ XDELETEVEC (mdswitches);
mdswitches = NULL;
n_mdswitches = 0;
--
2.30.2
next prev parent reply other threads:[~2023-12-07 16:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-02 21:24 Costas Argyris
2023-12-04 12:15 ` Jonathan Wakely
2023-12-06 14:29 ` Costas Argyris
2023-12-06 14:39 ` Jakub Jelinek
2023-12-07 14:28 ` Costas Argyris
2023-12-07 14:42 ` Jakub Jelinek
2023-12-07 15:16 ` Costas Argyris
2023-12-07 15:42 ` Jakub Jelinek
2023-12-07 16:01 ` Costas Argyris [this message]
2023-12-07 16:04 ` Jakub Jelinek
2023-12-08 12:18 ` Costas Argyris
2023-12-08 13:16 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHyHGCmN3cx8Nf44Mafq1bM4Ab98FQriujpwAC_98Bvyug0_+w@mail.gmail.com \
--to=costas.argyris@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=jwakely@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).