Skip to content

Commit f2d5bcc

Browse files
committed
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. Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20240229115149.749264-1-mpe@ellerman.id.au
1 parent 69b0194 commit f2d5bcc

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

arch/powerpc/boot/simple_alloc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ static void *simple_realloc(void *ptr, unsigned long size)
112112
return ptr;
113113

114114
new = simple_malloc(size);
115-
if (new)
115+
if (new) {
116116
memcpy(new, ptr, p->size);
117+
simple_free(ptr);
118+
}
117119

118-
simple_free(ptr);
119120
return new;
120121
}
121122

0 commit comments

Comments
 (0)