From ab1eae13ea414e4e4647b27fc89d2020f91680ce Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Fri, 18 Oct 2019 18:34:45 +0200
Subject: Fix strange bug in test malloc

With a certain program, this was failing to use the local malloc in the call
stack of the dlsym, which resulted in an infinite recursion and crash.  I have
no idea why, other than the optimizer is somehow at fault.  This fixes it.
---
 test/test_malloc.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

(limited to 'test')

diff --git a/test/test_malloc.c b/test/test_malloc.c
index 202db30..5803f93 100644
--- a/test/test_malloc.c
+++ b/test/test_malloc.c
@@ -29,8 +29,8 @@ static size_t        test_malloc_n_allocs   = 0;
 static size_t        test_malloc_fail_after = (size_t)-1;
 static volatile bool in_test_malloc_init    = false;
 
-void*
-malloc(size_t size)
+static void*
+test_malloc(size_t size)
 {
 	if (in_test_malloc_init) {
 		return NULL;  // dlsym is asking for memory, but handles this fine
@@ -46,10 +46,16 @@ malloc(size_t size)
 	return NULL;
 }
 
+void*
+malloc(size_t size)
+{
+	return test_malloc(size);
+}
+
 void*
 calloc(size_t nmemb, size_t size)
 {
-	void* ptr = malloc(nmemb * size);
+	void* ptr = test_malloc(nmemb * size);
 	if (ptr) {
 		memset(ptr, 0, nmemb * size);
 	}
-- 
cgit v1.2.1