bfd_arch_list() doc FUNCTION bfd_arch_list SYNOPSIS const char **bfd_arch_list (void); DESCRIPTION Return a freshly malloced NULL-terminated vector of the names of all the valid BFD architectures. Do not modify the names. _Return a freshly malloced_ grep gave me 3 hits of bfd_arch_list() call: $ grep -Irn 'bfd_arch_list' ./ ./bucomm.c:205: for (arch = bfd_arch_list (); *arch; arch++) ./windmc.c:250: const char **arch = bfd_arch_list (); ./windres.c:1076: const char **arch = bfd_arch_list(); Every time we don't save result of bfd_arch_list() and we don't free it.
These are all one-time uses, so they don't really leak.
Yes, sure, it's nothing _very_ important, but I don't know why it shouldn't be fixed. In list_supported_targets () [which is also used hardly ever] we free memory after bfd_target_list () call I attach patch to fix these memleaks, and change a little list_matching_formats () I think it's better.
Created attachment 2188 [details] free memory allocated by bfd_arch_list ()
Created attachment 2190 [details] Revised memory leak patch
Hi Jakub, Hi Andreas, I agree that there is no reason why we should not fix the leaks, so I have gone ahead and applied a slight variant of Jakub's patch (uploaded). The changes I made were: * Omitted the change to list_matching_formats(). There was no need for it and any decent compiler will produce the same code either way. * Moved the architecture walking variable ('arch') in the set_endianess() functions inside the if-statement. * Added a ChangeLog entry. Cheers Nick binutils/ChangeLog 2008-01-09 Jakub Zawadzki <darkjames@darkjames.ath.cx> PR binutils/55326 * bucomm.c (list_supported_architectures): Free architecture list after use. * windres.c (set_endianess): Likewise. * windmc.c (set_endianess): Likewise.