]> git.proxmox.com Git - swtpm.git/commitdiff
swtpm: Fix memory leak in case realloc fails
authorStefan Berger <stefanb@linux.ibm.com>
Fri, 30 Sep 2022 14:13:05 +0000 (10:13 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Fri, 30 Sep 2022 15:06:13 +0000 (11:06 -0400)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
src/swtpm/options.c

index 43256ad3c648cb6f4f7b3aac94681cb71eb30490..f89bee4c19d201f15e6e9f2b76a0d6267cfceb5d 100644 (file)
@@ -84,14 +84,16 @@ option_value_add(OptionValues *ovs, const OptionDesc optdesc, const char *val,
     long unsigned int lui;
     struct passwd *passwd;
     struct group *group;
-    
     size_t idx = ovs->n_options;
-    
-    ovs->options = realloc(ovs->options, (idx + 1) * sizeof(*ovs->options));
-    if (!ovs->options) {
+    void *tmp;
+
+    tmp = realloc(ovs->options, (idx + 1) * sizeof(*ovs->options));
+    if (!tmp) {
+        free(ovs->options);
         option_error_set(error, "Out of memory");
         return -1;
     }
+    ovs->options = tmp;
 
     ovs->n_options = idx + 1;
     ovs->options[idx].type = optdesc.type;