public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] selftest-arch: free arches array
@ 2021-07-02 10:56 Alexandra Hájková
  2021-07-03 22:03 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandra Hájková @ 2021-07-02 10:56 UTC (permalink / raw)
  To: gdb-patches

From: Alexandra Hájková <ahajkova@redhat.com>

Found by coverity scanning.

gdb/ChangeLog:

2021-07-02 Alexandra Hájková <ahajkova@redhat.com>

	* selftest-arch.c (struct gdbarch_selftest): free arches array
---
 gdb/selftest-arch.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c
index 0eef134d484..03b07108a2e 100644
--- a/gdb/selftest-arch.c
+++ b/gdb/selftest-arch.c
@@ -79,7 +79,9 @@ struct gdbarch_selftest : public selftest
 	  }
 
 	reset ();
+        free((char *)arches[i]);
       }
+      free(arches);
 
     SELF_CHECK (pass);
   }
-- 
2.26.3


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

* Re: [PATCH] selftest-arch: free arches array
  2021-07-02 10:56 [PATCH] selftest-arch: free arches array Alexandra Hájková
@ 2021-07-03 22:03 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2021-07-03 22:03 UTC (permalink / raw)
  To: Alexandra Hájková, gdb-patches



On 2021-07-02 6:56 a.m., Alexandra Hájková via Gdb-patches wrote:
> From: Alexandra Hájková <ahajkova@redhat.com>
> 
> Found by coverity scanning.
> 
> gdb/ChangeLog:
> 
> 2021-07-02 Alexandra Hájková <ahajkova@redhat.com>
> 
> 	* selftest-arch.c (struct gdbarch_selftest): free arches array
> ---
>   gdb/selftest-arch.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c
> index 0eef134d484..03b07108a2e 100644
> --- a/gdb/selftest-arch.c
> +++ b/gdb/selftest-arch.c
> @@ -79,7 +79,9 @@ struct gdbarch_selftest : public selftest
>   	  }
>   
>   	reset ();
> +        free((char *)arches[i]);

I don't think the elements of the array need to be freed, as here in 
gdbarch_printable_names, we just push the pointer handed by BFD, we 
don't duplicate the strings:

https://gitlab.com/gnutools/gdb/-/blob/3bdd3c041881470878cf47250a825a94d381fa64/gdb/gdbarch.c#L5580


>         }
> +      free(arches);

For this, I would suggest modernizing gdbarch_printable_names by making 
it return an std::vector instead.  It will simplify that code 
(gdbarch_printable_names) as well as the callers, making memory 
management automatic.

Simon

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

end of thread, other threads:[~2021-07-03 22:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-02 10:56 [PATCH] selftest-arch: free arches array Alexandra Hájková
2021-07-03 22:03 ` Simon Marchi

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