Skip to content

Commit

Permalink
src/utils: fix leaked groups and keys strings
Browse files Browse the repository at this point in the history
g_key_file_get_keys() and g_key_file_get_groups() both return
newly-allocated arrays of strings.
These need to be freed.

Fixes coverity issues:
| CID 1445509 (#2 of 2): Resource leak (RESOURCE_LEAK)
| 4. leaked_storage: Variable rem_groups going out of scope leaks the storage it points to

| CID 1445498 (#2 of 2): Resource leak (RESOURCE_LEAK)
| 5. leaked_storage: Variable rem_keys going out of scope leaks the storage it points to.

Signed-off-by: Enrico Joerns <[email protected]>
  • Loading branch information
ejoerns committed Mar 2, 2022
1 parent c6908d4 commit 9f07e75
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ gchar *resolve_path(const gchar *basefile, gchar *path)
gboolean check_remaining_groups(GKeyFile *key_file, GError **error)
{
gsize rem_num_groups;
gchar **rem_groups;
GStrv(rem_groups) = NULL;

rem_groups = g_key_file_get_groups(key_file, &rem_num_groups);
if (rem_num_groups != 0) {
Expand All @@ -170,7 +170,7 @@ gboolean check_remaining_groups(GKeyFile *key_file, GError **error)
gboolean check_remaining_keys(GKeyFile *key_file, const gchar *groupname, GError **error)
{
gsize rem_num_keys;
gchar **rem_keys;
GStrv(rem_keys) = NULL;

rem_keys = g_key_file_get_keys(key_file, groupname, &rem_num_keys, NULL);
if (rem_keys && rem_num_keys != 0) {
Expand Down

0 comments on commit 9f07e75

Please sign in to comment.