From ddbad3f4eae3e3b2ed41d8c541c01a0fb21a6e90 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 2 Dec 2020 15:20:13 -0800 Subject: [PATCH] gallium/osmesa: Fix leak of the ST manager/api on library unload. Closes: #883 Reviewed-by: Adam Jackson Part-of: --- src/gallium/frontends/osmesa/osmesa.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/gallium/frontends/osmesa/osmesa.c b/src/gallium/frontends/osmesa/osmesa.c index 5ce5f7b7da6..5c7f27d6dc2 100644 --- a/src/gallium/frontends/osmesa/osmesa.c +++ b/src/gallium/frontends/osmesa/osmesa.c @@ -134,9 +134,26 @@ osmesa_st_get_param(struct st_manager *smapi, enum st_manager_param param) 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();