https://gcc.gnu.org/g:0c775dcf3e78148204b78022dfd3de4a0833f496

commit r16-6721-g0c775dcf3e78148204b78022dfd3de4a0833f496
Author: Maciej W. Rozycki <[email protected]>
Date:   Mon Jan 12 13:08:28 2026 +0000

    libiberty: Make `objalloc_free' `free'-like WRT null pointer
    
    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.

Diff:
---
 libiberty/objalloc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libiberty/objalloc.c b/libiberty/objalloc.c
index 263d4b67a986..b3b255a1d65b 100644
--- a/libiberty/objalloc.c
+++ b/libiberty/objalloc.c
@@ -178,6 +178,10 @@ objalloc_free (struct objalloc *o)
 {
   struct objalloc_chunk *l;
 
+  /* Handle a nullptr as being a no-op. */
+  if (o == NULL)
+    return;
+
   l = (struct objalloc_chunk *) o->chunks;
   while (l != NULL)
     {

Reply via email to