Skip to content

Commit

Permalink
parse: plug a memory leak
Browse files Browse the repository at this point in the history
The variable "sequence" might not be released if we hit the assertion
assert_type() after having allocated storage for the string. The same
will happen if we reach the return in the if condition below
assert_type. Found by Coverity.
  • Loading branch information
daniloegea committed Jul 19, 2023
1 parent 1a7dd47 commit 3e2d7ed
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ handle_match_driver(NetplanParser* npp, yaml_node_t* node, __unused const char*
{
gboolean ret = FALSE;
yaml_node_t *elem = NULL;
GString *sequence = NULL;
g_autoptr(GString) sequence = NULL;

/* We overload the 'driver' setting for matches; such that it can either be a
* single scalar specifying a single driver glob/match, or a sequence of many
Expand All @@ -845,7 +845,6 @@ handle_match_driver(NetplanParser* npp, yaml_node_t* node, __unused const char*
return yaml_error(npp, node, error, "invalid sequence for 'driver'");

npp->current.netdef->match.driver = g_strdup(sequence->str);
g_string_free(sequence, TRUE);
ret = TRUE;
} else
return yaml_error(npp, node, error, "invalid type for 'driver': must be a scalar or a sequence of scalars");
Expand Down

0 comments on commit 3e2d7ed

Please sign in to comment.