Add filedata counting to watch for filedata leaks
authorOmari Stephens <xsdg@xsdg.org>
Tue, 13 Nov 2012 06:08:21 +0000 (06:08 +0000)
committerOmari Stephens <xsdg@xsdg.org>
Tue, 13 Nov 2012 08:24:48 +0000 (08:24 +0000)
This basically counts the number of filedata instances in existence at
any given point in time.  If the number doesn't drop down to where it's
supposed to be, there are leaks.

src/filedata.c

index 6adafc2..95f74d6 100644 (file)
 
 #include <errno.h>
 
 
 #include <errno.h>
 
+#ifdef DEBUG_FILEDATA
+gint global_file_data_count = 0;
+#endif
+
 static GHashTable *file_data_pool = NULL;
 static GHashTable *file_data_planned_change_hash = NULL;
 
 static GHashTable *file_data_pool = NULL;
 static GHashTable *file_data_planned_change_hash = NULL;
 
@@ -383,6 +387,10 @@ static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean
                }
 
        fd = g_new0(FileData, 1);
                }
 
        fd = g_new0(FileData, 1);
+#ifdef DEBUG_FILEDATA
+       global_file_data_count++;
+       DEBUG_2("file data count++: %d", global_file_data_count);
+#endif
 
        fd->size = st->st_size;
        fd->date = st->st_mtime;
 
        fd->size = st->st_size;
        fd->date = st->st_mtime;
@@ -534,6 +542,11 @@ static void file_data_free(FileData *fd)
        g_assert(fd->ref == 0);
        g_assert(!fd->locked);
 
        g_assert(fd->ref == 0);
        g_assert(!fd->locked);
 
+#ifdef DEBUG_FILEDATA
+       global_file_data_count--;
+       DEBUG_2("file data count--: %d", global_file_data_count);
+#endif
+
        metadata_cache_free(fd);
        g_hash_table_remove(file_data_pool, fd->original_path);
 
        metadata_cache_free(fd);
        g_hash_table_remove(file_data_pool, fd->original_path);