From dcc83cca07aee215047775fbb9aadff141a6624a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 22 Jan 2016 14:01:56 +0100 Subject: [PATCH] renderer: unref resource when destroying hashtable element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resources are reference-counted, if another object holds a reference to a resource, it should not free it. Change the resource hashtable destroy callback to unref. Currently, this doesn't happen, since the resource hashtable is kept until the renderer is reset. However, in the next commit, the destroy callback will be used if a resource is replaced in the hashtable, and we want to keep the original resource. Furthermore, even if replace shouldn't happen, it avoids confusion and future errors if use only reference-counting mechanism. Signed-off-by: Marc-André Lureau --- src/vrend_renderer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 4f189c5..826feb7 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -4236,7 +4236,9 @@ void vrend_renderer_resource_destroy(struct vrend_resource *res, bool remove) static void vrend_destroy_resource_object(void *obj_ptr) { struct vrend_resource *res = obj_ptr; - vrend_renderer_resource_destroy(res, false); + + if (pipe_reference(&res->base.reference, NULL)) + vrend_renderer_resource_destroy(res, false); } void vrend_renderer_resource_unref(uint32_t res_handle)