mirror of
https://github.com/stefanberger/swtpm.git
synced 2025-08-22 19:04:35 +00:00
swtpm: Fix memory leak in case realloc fails
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
8cbb6dae18
commit
c94a1c4cbd
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user