]> git.cworth.org Git - fips/commitdiff
metrics: Fix to not try to call into OpenGL at atexit time.
authorCarl Worth <cworth@cworth.org>
Thu, 31 Oct 2013 23:15:05 +0000 (16:15 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 31 Oct 2013 23:26:11 +0000 (16:26 -0700)
This could lead to all kinds of problems since the OpenGL call should
be long-gone by the time of atexit.

metrics.c

index 87da77834854e915dadb557e46d0a45c1dc10bb8..4e67ab9399de20b195e5704f57aaa1818dfa4eb4 100644 (file)
--- a/metrics.c
+++ b/metrics.c
@@ -865,14 +865,52 @@ print_program_metrics (void)
        free (sorted);
 }
 
-/* Called at program exit */
+/* Called at program exit.
+ *
+ * This is similar to metrics_info_fini, but only frees any used
+ * memory. Notably, it does not call any OpenGL functions, (since the
+ * OpenGL context no longer exists at program exit).
+ */
 static void
 metrics_exit (void)
 {
+       context_t *ctx = &current_context;
+       metrics_info_t *info = &ctx->metrics_info;
+       unsigned i;
+       timer_query_t *timer, *timer_next;
+       monitor_t *monitor, *monitor_next;
+
        if (verbose)
                printf ("fips: terminating\n");
 
-       metrics_info_fini ();
+       if (! info->initialized)
+               return;
+
+       for (timer = ctx->timer_head;
+            timer;
+            timer = timer_next)
+       {
+               timer_next = timer->next;
+               free (timer);
+       }
+
+       for (monitor = ctx->monitor_head;
+            monitor;
+            monitor = monitor_next)
+       {
+               monitor_next = monitor->next;
+               free (monitor);
+       }
+
+       for (i = 0; i < info->num_groups; i++)
+               metrics_group_info_fini (&info->groups[i]);
+
+       free (info->groups);
+
+       for (i = 0; i < info->num_shader_stages; i++)
+               free (info->stages[i].name);
+
+       free (info->stages);
 }
 
 void