]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efivars: don't bother with realloc() if we have no interest in the old data
authorLennart Poettering <lennart@poettering.net>
Thu, 13 Nov 2025 11:12:30 +0000 (12:12 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 13 Nov 2025 11:37:08 +0000 (12:37 +0100)
We shouldn't ask glibc to keep the old data around (which realloc() is
about), given we overwrite it entirely anyway. Let's hence speed things
up here, and allow glibc to just allocate a new block for us (and
shorten the code a bit)

src/basic/efivars.c

index b5e12eda62ce288ad34360f5d1b73416f618dc2f..9687f3d0e642a5e2701926b12aabf035e09c3fb5 100644 (file)
@@ -81,10 +81,10 @@ int efi_get_variable(
                 }
 
                 /* We want +1 for the read call, and +3 for the additional terminating bytes added below. */
-                char *t = realloc(buf, (size_t) st.st_size + MAX(1, 3));
-                if (!t)
+                free(buf);
+                buf = malloc((size_t) st.st_size + MAX(1, 3));
+                if (!buf)
                         return -ENOMEM;
-                buf = t;
 
                 const struct iovec iov[] = {
                         { &attr, sizeof(attr) },