public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey via Gdb-patches <gdb-patches@sourceware.org>,
	gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: Re: [PATCH] Fix two Python calls that don't check for errors
Date: Mon, 03 Jul 2023 17:28:33 +0100	[thread overview]
Message-ID: <875y71m026.fsf@redhat.com> (raw)
In-Reply-To: <20230629131256.4002834-1-tromey@adacore.com>

Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:

> PyModule_AddObject steals a reference on success, but not on error,
> which is why we have gdb_pymodule_addobject.  I found one spot still
> calling the former, which could in theory leak memory on failure.
> This patch fixes this.
>
> In the same function I found an unchecked call to
> PyDict_SetItemString.  This patch fixes this as well.

Thanks for fixing this.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

> ---
>  gdb/python/py-disasm.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c
> index 0af089f6b3e..6f0fed137e6 100644
> --- a/gdb/python/py-disasm.c
> +++ b/gdb/python/py-disasm.c
> @@ -1647,11 +1647,15 @@ gdbpy_initialize_disasm ()
>    gdb_disassembler_module = PyModule_Create (&python_disassembler_module_def);
>    if (gdb_disassembler_module == nullptr)
>      return -1;
> -  PyModule_AddObject(gdb_module, "disassembler", gdb_disassembler_module);
> +  if (gdb_pymodule_addobject (gdb_module, "disassembler",
> +			      gdb_disassembler_module) < 0)
> +    return -1;
>  
>    /* This is needed so that 'import _gdb.disassembler' will work.  */
>    PyObject *dict = PyImport_GetModuleDict ();
> -  PyDict_SetItemString (dict, "_gdb.disassembler", gdb_disassembler_module);
> +  if (PyDict_SetItemString (dict, "_gdb.disassembler",
> +			    gdb_disassembler_module) < 0)
> +    return -1;
>  
>    for (int i = 0; i <= (int) dis_style_comment_start; ++i)
>      {
> -- 
> 2.40.1


      reply	other threads:[~2023-07-03 16:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-29 13:12 Tom Tromey
2023-07-03 16:28 ` Andrew Burgess [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=875y71m026.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.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).