[nautilus] file-operations: Don't unref NULL hash table



commit 8005046fe96803ca62662657134f12bd5659d1cf
Author: António Fernandes <antoniof gnome org>
Date:   Sun Jan 17 23:57:15 2021 +0000

    file-operations: Don't unref NULL hash table
    
    The SOURCE_INFO_INIT sets the hash table pointer to NULL, and we may go
    out of scope before/without calling scan_sources(). So, it's wrong to
    assume that .scanned_dirs_info is not NULL.
    
    Interestingly, this didn't break the tests in either the MR or the
    main branch. But it did break the move-files test in another branch
    after being rebased, because that branch added an early return which
    precedes scan_sources(). Thank you tests, and thank you CI!

 src/nautilus-file-operations.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index ed2feda10..9b721dd71 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -227,7 +227,10 @@ typedef struct
 static void
 source_info_clear (SourceInfo *source_info)
 {
-    g_hash_table_unref (source_info->scanned_dirs_info);
+    if (source_info->scanned_dirs_info != NULL)
+    {
+        g_hash_table_unref (source_info->scanned_dirs_info);
+    }
 }
 
 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (SourceInfo, source_info_clear)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]