[Piglit] [PATCH v2] arb_direct_state_access: Fix memory leak.

Vinson Lee vlee at freedesktop.org
Fri Jan 9 17:45:59 PST 2015


Fix resource leak defect reported by Coverity.

Also move piglit_rgbw_image_ubyte call outside of loop as suggested by
Brian Paul.

Signed-off-by: Vinson Lee <vlee at freedesktop.org>
---
 tests/spec/arb_direct_state_access/getcompressedtextureimage.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tests/spec/arb_direct_state_access/getcompressedtextureimage.c b/tests/spec/arb_direct_state_access/getcompressedtextureimage.c
index 734ef72..9546af5 100644
--- a/tests/spec/arb_direct_state_access/getcompressedtextureimage.c
+++ b/tests/spec/arb_direct_state_access/getcompressedtextureimage.c
@@ -96,13 +96,15 @@ make_layer_data(int num_layers)
 	int z;
 	GLubyte *layer_data =
 		malloc(num_layers * IMAGE_SIZE * sizeof(GLubyte));
+	GLubyte *data = piglit_rgbw_image_ubyte(IMAGE_WIDTH,
+						IMAGE_HEIGHT, true);
 
 	for (z = 0; z < num_layers; z++) {
-		GLubyte *data = piglit_rgbw_image_ubyte(IMAGE_WIDTH,
-							IMAGE_HEIGHT, true);
 		memcpy(layer_data + IMAGE_SIZE * z, data, IMAGE_SIZE);
 	}
 
+	free(data);
+
 	/* Show the first layer of the completed layer data. */
 	show_image(layer_data, num_layers, "Test Data");
 
-- 
2.1.0



More information about the Piglit mailing list