public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Fix small objcopy memory leak
@ 2022-10-29  4:52 Alan Modra
  2022-10-31  9:24 ` Michael Tokarev
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2022-10-29  4:52 UTC (permalink / raw)
  To: binutils

	* objcopy.c (copy_archive): Free l->name.

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index d20aaef9f4f..03350babb69 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3744,6 +3744,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
 	    bfd_close (l->obfd);
 	    unlink (l->name);
 	  }
+	free ((char *) l->name);
 	next = l->next;
 	free (l);
       }

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: Fix small objcopy memory leak
  2022-10-29  4:52 Fix small objcopy memory leak Alan Modra
@ 2022-10-31  9:24 ` Michael Tokarev
  2022-10-31 10:18   ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Tokarev @ 2022-10-31  9:24 UTC (permalink / raw)
  To: Alan Modra, binutils

29.10.2022 07:52, Alan Modra via Binutils wrote:
> 	* objcopy.c (copy_archive): Free l->name.
> 
> diff --git a/binutils/objcopy.c b/binutils/objcopy.c
> index d20aaef9f4f..03350babb69 100644
> --- a/binutils/objcopy.c
> +++ b/binutils/objcopy.c
> @@ -3744,6 +3744,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
>   	    bfd_close (l->obfd);
>   	    unlink (l->name);
>   	  }
> +	free ((char *) l->name);

btw, why you cast it to char* ?

Thanks,

/mjt

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

* Re: Fix small objcopy memory leak
  2022-10-31  9:24 ` Michael Tokarev
@ 2022-10-31 10:18   ` Alan Modra
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Modra @ 2022-10-31 10:18 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: binutils

On Mon, Oct 31, 2022 at 12:24:21PM +0300, Michael Tokarev wrote:
> 29.10.2022 07:52, Alan Modra via Binutils wrote:
> > 	* objcopy.c (copy_archive): Free l->name.
> > 
> > diff --git a/binutils/objcopy.c b/binutils/objcopy.c
> > index d20aaef9f4f..03350babb69 100644
> > --- a/binutils/objcopy.c
> > +++ b/binutils/objcopy.c
> > @@ -3744,6 +3744,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
> >   	    bfd_close (l->obfd);
> >   	    unlink (l->name);
> >   	  }
> > +	free ((char *) l->name);
> 
> btw, why you cast it to char* ?

To explicitly remove the const qualifier.  Otherwise we hit a
-Wdiscarded-qualifiers warning when l->name, a const char*, is
implicitly cast to void* by the free() prototype.

-- 
Alan Modra
Australia Development Lab, IBM

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

end of thread, other threads:[~2022-10-31 10:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-29  4:52 Fix small objcopy memory leak Alan Modra
2022-10-31  9:24 ` Michael Tokarev
2022-10-31 10:18   ` Alan Modra

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