public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/guile: remove some manual xfree calls
@ 2023-05-31 20:49 Andrew Burgess
  2023-06-02 16:43 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2023-05-31 20:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

While working on another patch I had reason to look at
gdbscm_lookup_type, and noticed that we were making some manual calls
to xfree.

This commit switches to using gdb::unique_xmalloc_ptr<char> which
should automate the xfree calls.  I don't believe that we were leaking
memory before this commit -- this is just a cleanup.

There should be no user visible changes after this commit.
---
 gdb/guile/scm-type.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 033b800d8b0..cf2252c62e0 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -1267,15 +1267,16 @@ static SCM
 gdbscm_lookup_type (SCM name_scm, SCM rest)
 {
   SCM keywords[] = { block_keyword, SCM_BOOL_F };
-  char *name;
+  char *name_str;
   SCM block_scm = SCM_BOOL_F;
   int block_arg_pos = -1;
   const struct block *block = NULL;
   struct type *type;
 
   gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#O",
-			      name_scm, &name,
+			      name_scm, &name_str,
 			      rest, &block_arg_pos, &block_scm);
+  gdb::unique_xmalloc_ptr<char> name (name_str);
 
   if (block_arg_pos != -1)
     {
@@ -1284,13 +1285,9 @@ gdbscm_lookup_type (SCM name_scm, SCM rest)
       block = bkscm_scm_to_block (block_scm, block_arg_pos, FUNC_NAME,
 				  &exception);
       if (block == NULL)
-	{
-	  xfree (name);
-	  gdbscm_throw (exception);
-	}
+	gdbscm_throw (exception);
     }
-  type = tyscm_lookup_typename (name, block);
-  xfree (name);
+  type = tyscm_lookup_typename (name.get (), block);
 
   if (type != NULL)
     return tyscm_scm_from_type (type);

base-commit: e9683acf5e51c2bac8aa68d30d9ac3683dddcc7d
-- 
2.25.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb/guile: remove some manual xfree calls
  2023-05-31 20:49 [PATCH] gdb/guile: remove some manual xfree calls Andrew Burgess
@ 2023-06-02 16:43 ` Tom Tromey
  2023-06-05  9:35   ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-06-02 16:43 UTC (permalink / raw)
  To: Andrew Burgess via Gdb-patches; +Cc: Andrew Burgess

>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:

Andrew>        if (block == NULL)
Andrew> -	{
Andrew> -	  xfree (name);
Andrew> -	  gdbscm_throw (exception);
Andrew> -	}
Andrew> +	gdbscm_throw (exception);

Unfortunately I don't think this is the same.  IIUC, gdbscm_throw is a
noreturn function that calls longjmp.  So, the destructor will never be
run.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb/guile: remove some manual xfree calls
  2023-06-02 16:43 ` Tom Tromey
@ 2023-06-05  9:35   ` Andrew Burgess
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Burgess @ 2023-06-05  9:35 UTC (permalink / raw)
  To: Tom Tromey, Andrew Burgess via Gdb-patches

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Andrew>        if (block == NULL)
> Andrew> -	{
> Andrew> -	  xfree (name);
> Andrew> -	  gdbscm_throw (exception);
> Andrew> -	}
> Andrew> +	gdbscm_throw (exception);
>
> Unfortunately I don't think this is the same.  IIUC, gdbscm_throw is a
> noreturn function that calls longjmp.  So, the destructor will never be
> run.

You are correct.  Thanks for pointing this out.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-05  9:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-31 20:49 [PATCH] gdb/guile: remove some manual xfree calls Andrew Burgess
2023-06-02 16:43 ` Tom Tromey
2023-06-05  9:35   ` Andrew Burgess

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).