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 <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2025-10-17 00:30:18 +01:00
parent d904f77770
commit 0eb35e8032

View File

@@ -53,7 +53,7 @@ static gboolean
write_out_typelib (gchar *prefix, write_out_typelib (gchar *prefix,
GITypelib *typelib) GITypelib *typelib)
{ {
FILE *file; FILE *file, *file_owned = NULL;
gsize written; gsize written;
GFile *file_obj; GFile *file_obj;
gchar *filename; gchar *filename;
@@ -86,7 +86,7 @@ write_out_typelib (gchar *prefix,
file_obj = g_file_new_for_path (filename); file_obj = g_file_new_for_path (filename);
tmp_filename = g_strdup_printf ("%s.tmp", filename); tmp_filename = g_strdup_printf ("%s.tmp", filename);
tmp_file_obj = g_file_new_for_path (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) if (file == NULL)
{ {
@@ -106,8 +106,8 @@ write_out_typelib (gchar *prefix,
goto out; goto out;
} }
if (output != NULL) if (file_owned != NULL)
fclose (file); fclose (g_steal_pointer (&file_owned));
if (tmp_filename != NULL) if (tmp_filename != NULL)
{ {
if (!g_file_move (tmp_file_obj, file_obj, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) if (!g_file_move (tmp_file_obj, file_obj, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error))