[profiler] Don't leak counter data structures on shutdown.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Fri, 9 Sep 2016 05:21:17 +0000 (07:21 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Sun, 2 Oct 2016 16:24:15 +0000 (18:24 +0200)
mono/profiler/proflog.c

index 50f8276ed06e362e8410a4a1e7ed5d3649f5a49c..a6c1cb1da73ab375c0890ca263a6891a47810b4d 100644 (file)
@@ -3106,6 +3106,9 @@ static mono_mutex_t counters_mutex;
 static void
 counters_add_agent (MonoCounter *counter)
 {
+       if (in_shutdown)
+               return;
+
        MonoCounterAgent *agent, *item;
 
        mono_os_mutex_lock (&counters_mutex);
@@ -4180,6 +4183,22 @@ log_shutdown (MonoProfiler *prof)
                ign_res (write (prof->pipes [1], &c, 1));
                pthread_join (prof->helper_thread, &res);
        }
+
+       mono_os_mutex_destroy (&counters_mutex);
+
+       MonoCounterAgent *mc_next;
+
+       for (MonoCounterAgent *cur = counters; cur; cur = mc_next) {
+               mc_next = cur->next;
+               g_free (cur);
+       }
+
+       PerfCounterAgent *pc_next;
+
+       for (PerfCounterAgent *cur = perfcounters; cur; cur = pc_next) {
+               pc_next = cur->next;
+               g_free (cur);
+       }
 #endif
 #if USE_PERF_EVENTS
        if (perf_data) {