Skip to contentSkip to conversation

powerpc/boot: Only free if realloc() succeeds

PATCH Applied Michael Ellerman 2 participants 2 messages Feb 29, 2024 – Mar 13, 2024 PowerPC

lore
Share & tools
lore

Michael Ellerman

author reviewer
#0 lore raw

PATCH 1/1 powerpc/boot: Only free if realloc() succeeds

simple_realloc() frees the original buffer (ptr) even if the reallocation failed.

Fix it to behave like standard realloc() and only free the original buffer if the reallocation succeeded.

---
 arch/powerpc/boot/simple_alloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/boot/simple_alloc.c +3 -2
index db9aaa5face3..d07796fdf91a 100644
@@ -112,10 +112,11 @@ static void *simple_realloc(void *ptr, unsigned long size)
 		return ptr;
 
 	new = simple_malloc(size);
-	if (new)
+	if (new) {
 		memcpy(new, ptr, p->size);
+		simple_free(ptr);
+	}
 
-	simple_free(ptr);
 	return new;
 }
 
Signature · 1 line
2.43.2