diff --git a/tests/test_sorcery_memory_cache_thrash.c b/tests/test_sorcery_memory_cache_thrash.c
index daf5234710824e8c3fdd7384d4cbc4473cedd918..d911e869ef1dc04e8f69d6693c99bd45c923829c 100644
--- a/tests/test_sorcery_memory_cache_thrash.c
+++ b/tests/test_sorcery_memory_cache_thrash.c
@@ -304,6 +304,15 @@ static void sorcery_memory_cache_thrash_stop(struct sorcery_memory_cache_thrash
 		}
 
 		thread->stop = 1;
+	}
+
+	for (idx = 0; idx < AST_VECTOR_SIZE(&thrash->threads); ++idx) {
+		struct sorcery_memory_cache_thrash_thread *thread;
+
+		thread = AST_VECTOR_GET(&thrash->threads, idx);
+		if (thread->thread == AST_PTHREADT_NULL) {
+			continue;
+		}
 
 		pthread_join(thread->thread, NULL);