From 24b9751aaa2a7cea40ab282acd91bccda19152a7 Mon Sep 17 00:00:00 2001
From: Corey Farrell <git@cfware.com>
Date: Mon, 6 Nov 2017 18:33:13 -0500
Subject: [PATCH] test_sorcery_memory_cache_thrash: Handle error from vector
 append.

Cleanup resources when we fail to append the vector and report test
failure.

Change-Id: I6eb41586fd11dee8c0dfe35e91cb465a4cab7298
---
 tests/test_sorcery_memory_cache_thrash.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/test_sorcery_memory_cache_thrash.c b/tests/test_sorcery_memory_cache_thrash.c
index c0d25feb34..dfe7a7c81d 100644
--- a/tests/test_sorcery_memory_cache_thrash.c
+++ b/tests/test_sorcery_memory_cache_thrash.c
@@ -218,7 +218,11 @@ static struct sorcery_memory_cache_thrash *sorcery_memory_cache_thrash_create(co
 		/* This purposely holds no ref as the main thrash structure does */
 		thread->sorcery = thrash->sorcery;
 
-		AST_VECTOR_APPEND(&thrash->threads, thread);
+		if (AST_VECTOR_APPEND(&thrash->threads, thread)) {
+			ast_free(thread);
+			ao2_ref(thrash, -1);
+			return NULL;
+		}
 	}
 
 	return thrash;
-- 
GitLab