Linux 6.1.32
[platform/kernel/linux-starfive.git] / scripts / recordmcount.c
index cce12e1..ec692af 100644 (file)
@@ -102,6 +102,7 @@ static ssize_t uwrite(void const *const buf, size_t const count)
 {
        size_t cnt = count;
        off_t idx = 0;
+       void *p = NULL;
 
        file_updated = 1;
 
@@ -109,7 +110,10 @@ static ssize_t uwrite(void const *const buf, size_t const count)
                off_t aoffset = (file_ptr + count) - file_end;
 
                if (aoffset > file_append_size) {
-                       file_append = realloc(file_append, aoffset);
+                       p = realloc(file_append, aoffset);
+                       if (!p)
+                               free(file_append);
+                       file_append = p;
                        file_append_size = aoffset;
                }
                if (!file_append) {