Skip to content

Commit

Permalink
swtpm: Fix memory leak in case realloc fails
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Sep 30, 2022
1 parent 8cbb6da commit d438e06
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/swtpm/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d438e06

Please sign in to comment.