Skip to content

Commit

Permalink
src/config_file: NULL the variant_data more safely and checker-friendly
Browse files Browse the repository at this point in the history
Setting variant_data = NULL when checking for GError is valid as
key_file_consume_string() returns NULL on error. However, this can
confuse static checkers as Coverity that assume that variant_data might
have pointed to memory before.

Thus, to be safe, use g_clear_pointer() that would free any previous
data.

Fixes coverity issue:
| CID 1445500 (rauc#4 of 4): Resource leak (RESOURCE_LEAK)
| 19. overwrite_var: Overwriting variant_data in variant_data = NULL leaks the storage that variant_data points to.

Signed-off-by: Enrico Joerns <[email protected]>
  • Loading branch information
ejoerns committed Mar 1, 2022
1 parent 0313ce1 commit caa2bed
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ gboolean load_config(const gchar *filename, RaucConfig **config, GError **error)
/* parse 'variant-file' key */
variant_data = key_file_consume_string(key_file, "system", "variant-file", &ierror);
if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
variant_data = NULL;
g_clear_pointer(&variant_data, g_free);
g_clear_error(&ierror);
} else if (ierror) {
g_propagate_error(error, ierror);
Expand Down

0 comments on commit caa2bed

Please sign in to comment.