From c19b049d9c2ea54e248c064171f4c5c419e4252b Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 20 Mar 2016 11:13:30 +0000 Subject: [PATCH] igt/gem_concurent_blit: Prevent a memleak if we assert whilst creating buffers Assume that we may halt partway through buffers_create() and so be careful to clear up the partial state in buffers_destroy(). Signed-off-by: Chris Wilson --- tests/gem_concurrent_all.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c index 6122686e..f371f425 100644 --- a/tests/gem_concurrent_all.c +++ b/tests/gem_concurrent_all.c @@ -716,13 +716,28 @@ static void buffers_destroy(struct buffers *b) if (count == 0) return; - for (int i = 0; i < count; i++) { - b->mode->release_bo(b->src[i]); - b->mode->release_bo(b->dst[i]); - } - nop_release_bo(b->snoop); - b->mode->release_bo(b->spare); + /* Be safe so that we can clean up a partial creation */ b->count = 0; + for (int i = 0; i < count; i++) { + if (b->src[i]) { + b->mode->release_bo(b->src[i]); + b->src[i] = NULL; + } else + break; + + if (b->dst[i]) { + b->mode->release_bo(b->dst[i]); + b->dst[i] = NULL; + } + } + if (b->snoop) { + nop_release_bo(b->snoop); + b->snoop = NULL; + } + if (b->spare) { + b->mode->release_bo(b->spare); + b->spare = NULL; + } } static void buffers_create(struct buffers *b) @@ -732,6 +747,7 @@ static void buffers_create(struct buffers *b) buffers_destroy(b); igt_assert(b->count == 0); + b->count = count; for (int i = 0; i < count; i++) { b->src[i] = b->mode->create_bo(b); @@ -739,7 +755,6 @@ static void buffers_create(struct buffers *b) } b->spare = b->mode->create_bo(b); b->snoop = snoop_create_bo(b); - b->count = count; } static void buffers_fini(struct buffers *b)