From 0eb35e803249a5f044960219647d5ca8d8bfc9bb Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 17 Oct 2025 00:30:18 +0100 Subject: [PATCH] compiler: Fix a scan-build false positive about a file handle leak Seems scan-build is incorrectly assuming that `output != NULL` at the start of the function (so `file` is opened), and then later assuming that `output == NULL` (so `file` is not closed). Signed-off-by: Philip Withnall --- girepository/compiler/compiler.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/girepository/compiler/compiler.c b/girepository/compiler/compiler.c index c8e837554..f9d588d52 100644 --- a/girepository/compiler/compiler.c +++ b/girepository/compiler/compiler.c @@ -53,7 +53,7 @@ static gboolean write_out_typelib (gchar *prefix, GITypelib *typelib) { - FILE *file; + FILE *file, *file_owned = NULL; gsize written; GFile *file_obj; gchar *filename; @@ -86,7 +86,7 @@ write_out_typelib (gchar *prefix, file_obj = g_file_new_for_path (filename); tmp_filename = g_strdup_printf ("%s.tmp", filename); tmp_file_obj = g_file_new_for_path (tmp_filename); - file = g_fopen (tmp_filename, "wbe"); + file = file_owned = g_fopen (tmp_filename, "wbe"); if (file == NULL) { @@ -106,8 +106,8 @@ write_out_typelib (gchar *prefix, goto out; } - if (output != NULL) - fclose (file); + if (file_owned != NULL) + fclose (g_steal_pointer (&file_owned)); if (tmp_filename != NULL) { if (!g_file_move (tmp_file_obj, file_obj, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error))