]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efivars: fix potential memory leak
authorLuca Boccassi <luca.boccassi@gmail.com>
Fri, 17 Oct 2025 09:23:28 +0000 (10:23 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 17 Oct 2025 15:44:15 +0000 (16:44 +0100)
If 'ret' is not passed, 'x' is leaked

Follow-up for c8d60ae79d1763c6ef16fdb306b65d909a769de8

CID#1621673

src/basic/efivars.c

index 86544d1de26af964410b942af0b03698860d6b20..99c47e8ce2e9bde1a5a8db99ffa9139b6acedf4b 100644 (file)
@@ -155,9 +155,8 @@ int efi_get_variable(
 }
 
 int efi_get_variable_string(const char *variable, char **ret) {
-        _cleanup_free_ void *s = NULL;
+        _cleanup_free_ void *s = NULL, *x = NULL;
         size_t ss = 0;
-        char *x;
         int r;
 
         assert(variable);
@@ -171,7 +170,7 @@ int efi_get_variable_string(const char *variable, char **ret) {
                 return -ENOMEM;
 
         if (ret)
-                *ret = x;
+                *ret = TAKE_PTR(x);
 
         return 0;
 }