public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Nieper-Wißkirchen" <marc.nieper+gnu@gmail.com>
To: David Malcolm <dmalcolm@redhat.com>
Cc: "Marc Nieper-Wißkirchen" <marc.nieper+gnu@gmail.com>,
	"Alex Coplan" <Alex.Coplan@arm.com>,
	"Mark Wielaard" <mark@klomp.org>,
	"jit@gcc.gnu.org" <jit@gcc.gnu.org>,
	"Joseph Myers" <joseph@codesourcery.com>
Subject: Re: Memory leaks (detected by Valgrind)
Date: Sat, 18 Dec 2021 20:36:26 +0100	[thread overview]
Message-ID: <CAEYrNrSc0kh=mqkLH1XjJbFb_u8jT=bsoo1FoJ_1+jNHY4YakQ@mail.gmail.com> (raw)
In-Reply-To: <07714a8d9583dd2ebfe548f5c066d6d2213434d7.camel@redhat.com>

Am Sa., 18. Dez. 2021 um 17:45 Uhr schrieb David Malcolm <dmalcolm@redhat.com>:

[...]

> IIRC I tried that approach, and the maintainer (Joseph Myers, I think),
> wasn't keen on it, but this was a few years ago.  I've tried finding
> the discussion in the archives, but couldn't.  IIRC, he preferred
> adding a flag to strings in gcc.c, tracking if they needed to be freed.
> I'm CCing Joseph.   FWIW there's a class in libcpp/include/line-map.h:
> class label_text which does this.  Perhaps it could be used for this
> (and maybe renamed???)

Using label_text (suitably renamed) everywhere looks like the most
elegant solution but it would be a very invasive change to the
existing code of gcc.c. It contains and uses a lot of functions that
handle strings and allocate new ones (like find_file or concat), which
would have to be rewritten to take a label_text argument.

A much simpler solution is IMO to maintain a vector of pointers that
have to be eventually freed. A function

template <typename T>
T *gc (T *s)

adds the argument to the vector of addresses to be garbage-collected
(= freed) later.

Many calls to, say, concat would then be rewritten in the form

gc (concat (...))

Marc

      parent reply	other threads:[~2021-12-18 19:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 17:17 Marc Nieper-Wißkirchen
2021-12-16 22:00 ` Marc Nieper-Wißkirchen
2021-12-16 22:26   ` Mark Wielaard
2021-12-17 10:29     ` Marc Nieper-Wißkirchen
2021-12-17 10:52       ` Alex Coplan
2021-12-17 14:03         ` Marc Nieper-Wißkirchen
2021-12-17 14:54           ` Andrea Corallo
2021-12-17 15:11             ` Marc Nieper-Wißkirchen
2021-12-17 16:07               ` Andrea Corallo
2021-12-17 17:53                 ` Marc Nieper-Wißkirchen
2021-12-17 18:48                   ` Andrea Corallo
2021-12-17 23:22         ` David Malcolm
2021-12-18 13:57           ` Marc Nieper-Wißkirchen
2021-12-18 16:45             ` David Malcolm
2021-12-18 17:50               ` Marc Nieper-Wißkirchen
2021-12-18 19:36               ` Marc Nieper-Wißkirchen [this message]

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='CAEYrNrSc0kh=mqkLH1XjJbFb_u8jT=bsoo1FoJ_1+jNHY4YakQ@mail.gmail.com' \
    --to=marc.nieper+gnu@gmail.com \
    --cc=Alex.Coplan@arm.com \
    --cc=dmalcolm@redhat.com \
    --cc=jit@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=mark@klomp.org \
    /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).