summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Cardace <acardace@redhat.com>2020-09-01 18:38:45 +0200
committerThomas Haller <thaller@redhat.com>2020-09-08 12:42:13 +0200
commita945082a5a9c90651720bbd96e79c90c41fc121f (patch)
tree9c3393374c29a1eed8552247ca5ad79130eff33f
parent2e7fc7afd275a4e54eaf40d6ff7d0e0f6cbbaf96 (diff)
downloadNetworkManager-th/nm-1-20.tar.gz
initrd: fix memory leakth/nm-1-20
Signed-off-by: Antonio Cardace <acardace@redhat.com> Fixes: 9f9609555d1c ('initrd: add configuration generator') (cherry picked from commit d5c05d07c7aff317284d2d5197d75e0f605b4364) (cherry picked from commit bba54613eb4255166c921844e8b6d2a2bd0000a1) (cherry picked from commit 67bb9896b33d8d7b527ce33919b33456672265d0) (cherry picked from commit 5913e4cee97127eca26c6a74207cbe136fed7333)
-rw-r--r--shared/nm-glib-aux/nm-macros-internal.h8
-rw-r--r--src/initrd/nm-initrd-generator.c2
2 files changed, 9 insertions, 1 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h
index 9502c442ec..e36e7af7fe 100644
--- a/shared/nm-glib-aux/nm-macros-internal.h
+++ b/shared/nm-glib-aux/nm-macros-internal.h
@@ -231,6 +231,14 @@ NM_AUTO_DEFINE_FCN0 (GError *, gs_local_free_error, g_error_free)
#define gs_unref_keyfile nm_auto(gs_local_keyfile_unref)
NM_AUTO_DEFINE_FCN0 (GKeyFile *, gs_local_keyfile_unref, g_key_file_unref)
+/**
+ * gs_free_option_context:
+ *
+ * Call g_option_context_free() on a variable location when it goes out of scope.
+ */
+#define gs_free_option_context nm_auto(gs_local_option_context)
+NM_AUTO_DEFINE_FCN0 (GOptionContext *, gs_local_option_context, g_option_context_free);
+
/*****************************************************************************/
#include "nm-glib.h"
diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c
index 0ff3428e28..4603813013 100644
--- a/src/initrd/nm-initrd-generator.c
+++ b/src/initrd/nm-initrd-generator.c
@@ -90,7 +90,7 @@ main (int argc, char *argv[])
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL, NULL },
{ NULL }
};
- GOptionContext *option_context;
+ gs_free_option_context GOptionContext *option_context = NULL;
GError *error = NULL;
int errsv;