question about memory allocate and free

Nick Clifton nickc@redhat.com
Tue Mar 7 08:24:00 GMT 2006


Hi Ligang,

> 1. In Binutils source, the memory allcating functions are xmalloc() and
> obstack_begin().
> but, a lot of allocated memory are not set free by free() or
> obstack_free(). why? 

Bugs (mostly).  Some times it is too difficult to know when it is safe 
to free the memory, but most of the time any failure to free allocated 
memory is a bug.

> Dose it result in memory leak?

Yes.  Although probably not for very long.  ie the memory is mostly 
likely needed right up until the BFD library has finished its work, at 
which point it is presumed that the client using the library will have 
finished its work as well, and so it will be terminating.

> 2. In added files for porting Binutils, need i release allocated memeoy and
> which
> function should i use?

bfd_alloc() and bfd_free() or their related functions.  These are all 
defined in bfd/opncls.c.

Cheers
   Nick





More information about the Binutils mailing list