Mesa (master): svga: don't reference count svga_sampler_view's texture
Brian Paul
brianp at kemper.freedesktop.org
Wed Jan 11 20:11:02 UTC 2012
Module: Mesa
Branch: master
Commit: dce4c368b5536716770e5cabef0321db8537a6d9
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=dce4c368b5536716770e5cabef0321db8537a6d9
Author: Brian Paul <brianp at vmware.com>
Date: Wed Jan 11 19:52:23 2012 +0100
svga: don't reference count svga_sampler_view's texture
svga_sampler_view contains a pointer to a pipe_resource (base class of
svga_texture) and svga_texture contains a pointer to an svga_sampler_view.
This circular dependency prevented the objects from ever being freed when
they pointed to each other. Make the svga_sampler_view::texture pointer
a "weak reference" (no reference counting) to break the dependency.
This is safe to do because the pipe_resource/texture always has a longer
lifespan than the sampler view so when svga_sampler_view stops referencing
the texture, the texture's refcount never hits zero.
Fixes a memory leak seen with google earth and other apps.
Reviewed-by: Jakob Bornecrantz <jakob at vmware.com>
---
src/gallium/drivers/svga/svga_sampler_view.c | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/gallium/drivers/svga/svga_sampler_view.c b/src/gallium/drivers/svga/svga_sampler_view.c
index b756b07..e8234d6 100644
--- a/src/gallium/drivers/svga/svga_sampler_view.c
+++ b/src/gallium/drivers/svga/svga_sampler_view.c
@@ -105,7 +105,12 @@ svga_get_tex_sampler_view(struct pipe_context *pipe,
sv = CALLOC_STRUCT(svga_sampler_view);
pipe_reference_init(&sv->reference, 1);
- pipe_resource_reference(&sv->texture, pt);
+
+ /* Note: we're not refcounting the texture resource here to avoid
+ * a circular dependency.
+ */
+ sv->texture = pt;
+
sv->min_lod = min_lod;
sv->max_lod = max_lod;
@@ -206,6 +211,11 @@ svga_destroy_sampler_view_priv(struct svga_sampler_view *v)
SVGA_DBG(DEBUG_DMA, "unref sid %p (sampler view)\n", v->handle);
svga_screen_surface_destroy(ss, &v->key, &v->handle);
}
- pipe_resource_reference(&v->texture, NULL);
+
+ /* Note: we're not refcounting the texture resource here to avoid
+ * a circular dependency.
+ */
+ v->texture = NULL;
+
FREE(v);
}
More information about the mesa-commit
mailing list