swtpm: Fix memory leak in case realloc fails

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2022-09-30 10:13:05 -04:00 committed by Stefan Berger
parent 8cbb6dae18
commit c94a1c4cbd

View 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;
void *tmp;
ovs->options = realloc(ovs->options, (idx + 1) * sizeof(*ovs->options));
if (!ovs->options) {
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;