Fix small objcopy memory leak

Alan Modra amodra@gmail.com
Mon Oct 31 10:18:04 GMT 2022


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


More information about the Binutils mailing list