[PATCH] libiberty: Make `objalloc_free' `free'-like WRT null pointer
Maciej W. Rozycki
macro@redhat.com
Wed Jan 7 09:30:31 GMT 2026
Inspired by a suggestion from Jan Beulich to make one of `objalloc_free'
callers `free'-like with respect to null pointer argument handling make
the function return with no action taken rather than crashing when such
a pointer is passed. This is to make the API consistent with ISO C and
to relieve all the callers from having to check for a null pointer.
libiberty/
* objalloc.c (objalloc_free): Don't use the pointer passed if
null.
---
Hi,
This has been raised in a binutils patch review[1]. OK to apply, and
then right away, since libiberty is an auxiliary library and technically
not a part of the compiler suite, plus the change should be trivially
safe?
References:
[1] "BFD: Prevent a crash on freeing a BFD's uninitialized section hash",
<https://inbox.sourceware.org/binutils/23685606-02a1-4416-978a-3c9907c5a171@suse.com/>.
Maciej
---
libiberty/objalloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
binutils-libiberty-objalloc-free-null.diff
Index: binutils-gdb/libiberty/objalloc.c
===================================================================
--- binutils-gdb.orig/libiberty/objalloc.c
+++ binutils-gdb/libiberty/objalloc.c
@@ -178,7 +178,7 @@ objalloc_free (struct objalloc *o)
{
struct objalloc_chunk *l;
- l = (struct objalloc_chunk *) o->chunks;
+ l = o != NULL ? (struct objalloc_chunk *) o->chunks : NULL;
while (l != NULL)
{
struct objalloc_chunk *next;
More information about the Binutils
mailing list