gfilenamecompleter: Fix g_object_unref() of undefined value

If the first `goto out` is taken, `file` has not yet been initialised,
but `g_clear_object (&file)` is called on it, and things get unhappy.

Fix that by following standard convention and initialising
‘autoptr’-like variables at declaration time.

Spotted by scan-build in
https://gitlab.gnome.org/GNOME/glib/-/jobs/5321883.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>


(cherry picked from commit a41d1681be)

Co-authored-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Michael Catanzaro
2025-07-22 07:51:10 -05:00
parent f5a5c2a9b3
commit 45d95e1a35

View File

@@ -342,7 +342,7 @@ init_completion (GFilenameCompleter *completer,
char **basename_out)
{
gboolean should_escape;
GFile *file, *parent;
GFile *file = NULL, *parent = NULL;
char *basename;
char *t;
size_t len;