[Mesa-dev] [PATCH] r600g: Cleaned up index buffer reference handling in the draw module.

Tilman Sauerbeck tilman at code-monkey.de
Sun Sep 26 10:28:25 PDT 2010


This fixes a buffer leak.

Signed-off-by: Tilman Sauerbeck <tilman at code-monkey.de>
---
 src/gallium/drivers/r600/r600_buffer.c |    5 ++++-
 src/gallium/drivers/r600/r600_draw.c   |    4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/r600/r600_buffer.c b/src/gallium/drivers/r600/r600_buffer.c
index 1621b2a..d734e23 100644
--- a/src/gallium/drivers/r600/r600_buffer.c
+++ b/src/gallium/drivers/r600/r600_buffer.c
@@ -280,7 +280,10 @@ int r600_upload_index_buffer(struct r600_context *rctx,
 			goto done;
 		}
 		draw->index_buffer_offset = index_offset;
-		draw->index_buffer = upload_buffer;
+
+		/* Transfer ownership. */
+		pipe_resource_reference(&draw->index_buffer, upload_buffer);
+		pipe_resource_reference(&upload_buffer, NULL);
 	}
 
 done:
diff --git a/src/gallium/drivers/r600/r600_draw.c b/src/gallium/drivers/r600/r600_draw.c
index afc3b7b..c41156f 100644
--- a/src/gallium/drivers/r600/r600_draw.c
+++ b/src/gallium/drivers/r600/r600_draw.c
@@ -168,7 +168,7 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
 					    info->count);
 
 		draw.index_size = rctx->index_buffer.index_size;
-		draw.index_buffer = rctx->index_buffer.buffer;
+		pipe_resource_reference(&draw.index_buffer, rctx->index_buffer.buffer);
 		draw.index_buffer_offset = draw.start * draw.index_size;
 		draw.start = 0;
 		r600_upload_index_buffer(rctx, &draw);
@@ -185,4 +185,6 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
 	r = r600_draw_common(&draw);
 	if (r)
 	  fprintf(stderr,"draw common failed %d\n", r);
+
+	pipe_resource_reference(&draw.index_buffer, NULL);
 }
-- 
1.7.2.3



More information about the mesa-dev mailing list