[Spice-devel] [PATCH spice-server 03/20] Free statistic file on spice_server_destroy

Frediano Ziglio fziglio at redhat.com
Thu Nov 24 17:38:50 UTC 2016


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/reds.c                 |  4 ++++
 server/stat-file.c            | 17 +++++++++++++++++
 server/stat-file.h            |  1 +
 server/tests/stat-file-test.c |  2 ++
 4 files changed, 24 insertions(+)

diff --git a/server/reds.c b/server/reds.c
index 0e68973..1b1c737 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3599,6 +3599,10 @@ SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer *reds)
     pthread_mutex_lock(&global_reds_lock);
     servers = g_list_remove(servers, reds);
     pthread_mutex_unlock(&global_reds_lock);
+
+#ifdef RED_STATISTICS
+    stat_file_free(reds->stat_file);
+#endif
 }
 
 SPICE_GNUC_VISIBLE spice_compat_version_t spice_get_current_compat_version(void)
diff --git a/server/stat-file.c b/server/stat-file.c
index d1e25ce..beed77a 100644
--- a/server/stat-file.c
+++ b/server/stat-file.c
@@ -80,6 +80,23 @@ cleanup:
     return NULL;
 }
 
+void stat_file_free(RedStatFile *stat_file)
+{
+    if (!stat_file) {
+        return;
+    }
+
+    stat_file_unlink(stat_file);
+    /* TODO other part of the code is not ready for this! */
+#if 0
+    size_t shm_size = STAT_SHM_SIZE(stat_file->max_nodes);
+    munmap(stat_file->stat, shm_size);
+#endif
+
+    pthread_mutex_destroy(&stat_file->lock);
+    free(stat_file);
+}
+
 const char *stat_file_get_shm_name(RedStatFile *stat_file)
 {
     return stat_file->shm_name;
diff --git a/server/stat-file.h b/server/stat-file.h
index 903b68b..0454e2e 100644
--- a/server/stat-file.h
+++ b/server/stat-file.h
@@ -27,6 +27,7 @@ typedef uint32_t StatNodeRef;
 typedef struct RedStatFile RedStatFile;
 
 RedStatFile *stat_file_new(unsigned int max_nodes);
+void stat_file_free(RedStatFile *stat_file);
 void stat_file_unlink(RedStatFile *file_stat);
 const char *stat_file_get_shm_name(RedStatFile *stat_file);
 StatNodeRef stat_file_add_node(RedStatFile *stat_file, StatNodeRef parent,
diff --git a/server/tests/stat-file-test.c b/server/tests/stat-file-test.c
index 09b0c7a..40cf37d 100644
--- a/server/tests/stat-file-test.c
+++ b/server/tests/stat-file-test.c
@@ -93,6 +93,8 @@ static void stat_file(void)
     g_assert_null(stat_file_get_shm_name(stat_file));
     g_assert_cmpint(access(filename, F_OK),==,-1);
     free(filename);
+
+    stat_file_free(stat_file);
 }
 
 int main(int argc, char *argv[])
-- 
2.9.3



More information about the Spice-devel mailing list