diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2016-03-20 11:13:30 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2016-03-20 11:17:21 +0000 |
commit | c19b049d9c2ea54e248c064171f4c5c419e4252b (patch) | |
tree | a444c479cc4576b0165db0988dc663b42abf1845 /tests/gem_concurrent_all.c | |
parent | 3d8af56ed2f08e57e58944c1baf8dc15fafa3f27 (diff) |
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 <chris@chris-wilson.co.uk>
Diffstat (limited to 'tests/gem_concurrent_all.c')
-rw-r--r-- | tests/gem_concurrent_all.c | 27 |
1 files changed, 21 insertions, 6 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; + /* Be safe so that we can clean up a partial creation */ + b->count = 0; for (int i = 0; i < count; i++) { - b->mode->release_bo(b->src[i]); - b->mode->release_bo(b->dst[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; } - nop_release_bo(b->snoop); - b->mode->release_bo(b->spare); - b->count = 0; } 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) |