From 9ed8b871bb6468cd018afb2675b85206645776cc Mon Sep 17 00:00:00 2001 From: Antonio Cardace Date: Tue, 1 Sep 2020 18:38:45 +0200 Subject: [PATCH] initrd: fix memory leak Signed-off-by: Antonio Cardace 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) --- shared/nm-glib-aux/nm-macros-internal.h | 8 ++++++++ src/initrd/nm-initrd-generator.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) 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;