summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Cardace <acardace@redhat.com>2020-09-01 18:38:45 +0200
committerAntonio Cardace <acardace@redhat.com>2020-09-01 19:05:10 +0200
commitd5c05d07c7aff317284d2d5197d75e0f605b4364 (patch)
treedeaf75054d4486b904db2ab4cbf73b2cdba2f5b7
parentd619de7727f8fd56c44152c741abef4f0dd2e231 (diff)
downloadNetworkManager-d5c05d07c7aff317284d2d5197d75e0f605b4364.tar.gz
initrd: fix memory leak
Signed-off-by: Antonio Cardace <acardace@redhat.com> Fixes: 9f9609555d1c ('initrd: add configuration generator')
-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 6fd3dc2ec9..c61ef65254 100644
--- a/shared/nm-glib-aux/nm-macros-internal.h
+++ b/shared/nm-glib-aux/nm-macros-internal.h
@@ -141,6 +141,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 f984ed739c..5a93480bf2 100644
--- a/src/initrd/nm-initrd-generator.c
+++ b/src/initrd/nm-initrd-generator.c
@@ -83,7 +83,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;
gs_free_error GError *error = NULL;
gs_free char *hostname = NULL;
int errsv;