gallium/osmesa: Fix leak of the ST manager/api on library unload.
authorEric Anholt <eric@anholt.net>
Wed, 2 Dec 2020 23:20:13 +0000 (15:20 -0800)
committerEric Anholt <eric@anholt.net>
Sat, 5 Dec 2020 00:00:58 +0000 (16:00 -0800)
Closes: #883
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7886>

src/gallium/frontends/osmesa/osmesa.c

index 5ce5f7b..5c7f27d 100644 (file)
@@ -135,8 +135,25 @@ static struct st_manager *stmgr = NULL;
 static struct st_api *stapi = NULL;
 
 static void
+destroy_st_manager(void)
+{
+   if (stmgr) {
+      if (stmgr->screen)
+         stmgr->screen->destroy(stmgr->screen);
+      FREE(stmgr);
+   }
+
+   if (stapi && stapi->destroy) {
+      stapi->destroy(stapi);
+   }
+}
+
+static void
 create_st_manager(void)
 {
+   if (atexit(destroy_st_manager) != 0)
+      return;
+
    stmgr = CALLOC_STRUCT(st_manager);
    if (stmgr) {
       stmgr->screen = osmesa_create_screen();