From: Philipp Rudo <prudo@linux.vnet.ibm.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix memory leak in python.c:do_start_initialization
Date: Wed, 22 Mar 2017 17:52:00 -0000 [thread overview]
Message-ID: <20170322185224.40a2a37c@ThinkPad> (raw)
In-Reply-To: <fbf5af90-712e-7dac-371f-5ba4e2f066d8@redhat.com>
On Wed, 22 Mar 2017 15:19:16 +0000
Pedro Alves <palves@redhat.com> wrote:
> Hi Philipp,
>
> Thanks.
>
> On 03/22/2017 01:11 PM, Philipp Rudo wrote:
>
> > diff --git a/gdb/python/python.c b/gdb/python/python.c
> > index 73fb3d0..6b16613 100644
> > --- a/gdb/python/python.c
> > +++ b/gdb/python/python.c
> > @@ -1535,7 +1535,7 @@ extern initialize_file_ftype
> > _initialize_python; static bool
> > do_start_initialization ()
> > {
> > - char *progname;
> > + char *progname, *libdir;
> > #ifdef IS_PY3K
> > int i;
> > size_t progsize, count;
> > @@ -1550,8 +1550,10 @@ do_start_initialization ()
> > /foo/bin/python
> > /foo/lib/pythonX.Y/...
> > This must be done before calling Py_Initialize. */
> > - progname = concat (ldirname (python_libdir), SLASH_STRING, "bin",
> > + libdir = ldirname (python_libdir);
> > + progname = concat (libdir, SLASH_STRING, "bin",
> > SLASH_STRING, "python", (char *) NULL);
> > + xfree (libdir);
>
> Let's restrict the new variable to the #if block that needs it.
> I.e., declare the variable where is initialized, like:
>
> const char *libdir = ldirname (python_libdir);
> progname = concat (libdir, SLASH_STRING, "bin",
>
> OK with that change. Please push.
Shall I fix it? Or do we go with your ldirname fix?
>
> Note, you could have used reconcat instead of concat, avoiding the
> xfree call, and maybe one reallocation, but that's hardly an
> issue here.
Thought about using reconcat. But in the end reconcat would have done
the same -- calling free on libdir. Thats why I decided it would be
better readable when not hidden.
> Perhaps better overall would be to make ldirname return a std::string
> and eliminate these leaks "by design". It'd get rid of several
> make_cleanup calls throughout too. I'll give that a quick try.
Or maybe combining all path handling in a 'class gdbpath'. But
make ldirname return std::string definitely is an advantage.
>
> Thanks,
> Pedro Alves
>
next prev parent reply other threads:[~2017-03-22 17:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-22 13:11 Philipp Rudo
2017-03-22 13:11 ` [PATCH] Fix read after xfree in linux_nat_detach Philipp Rudo
2017-03-22 15:07 ` Pedro Alves
2017-03-22 17:17 ` Philipp Rudo
2017-03-22 17:26 ` Pedro Alves
2017-03-23 13:17 ` [PATCH v2] " Philipp Rudo
2017-03-23 13:42 ` Pedro Alves
[not found] ` <f712cd1a-cf44-44da-9bf4-3ccd407a76a0@redhat.com>
2017-04-12 8:14 ` Philipp Rudo
2017-03-22 15:19 ` [PATCH] Fix memory leak in python.c:do_start_initialization Pedro Alves
2017-03-22 17:52 ` Philipp Rudo [this message]
2017-03-22 18:45 ` Pedro Alves
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=20170322185224.40a2a37c@ThinkPad \
--to=prudo@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@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