From 64ca7a53f88b681634a33a673cbf2e91d99692e0 Mon Sep 17 00:00:00 2001 From: Damian Wrobel Date: Tue, 27 Feb 2018 15:27:51 +0100 Subject: [PATCH] fix SIGSEGV caused by redefining realloc() (#896) This fixes the following crash: Thread 3 "pxscene2dtests" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7f0703aff700 (LWP 6252)] 0x00007f070eea114c in __tsan_func_entry () from /lib64/libtsan.so.0 (gdb) bt #0 0x00007f070eea114c in __tsan_func_entry () from /lib64/libtsan.so.0 #1 0x00000000005af843 in realloc (ptr=0x0, size=32) at pxCore/tests/pxScene2d/test_imagecache.cpp:43 #2 0x00007f070a988645 in pthread_getattr_np (thread_id=, attr=) at pthread_getattr_np.c:176 #3 0x00007f070eeba185 in __sanitizer::GetThreadStackTopAndBottom(bool, unsigned long*, unsigned long*) () from /lib64/libtsan.so.0 #4 0x00007f070eeba617 in __sanitizer::GetThreadStackAndTls(bool, unsigned long*, unsigned long*, unsigned long*, unsigned long*) () from /lib64/libtsan.so.0 #5 0x00007f070eea8be6 in __tsan::ThreadStart(__tsan::ThreadState*, int, unsigned long) () from /lib64/libtsan.so.0 #6 0x00007f070ee4b7d6 in __tsan_thread_start_func () from /lib64/libtsan.so.0 #7 0x00007f070a98661b in start_thread (arg=0x7f0703aff700) at pthread_create.c:465 #8 0x00007f07092db98f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 --- tests/pxScene2d/test_imagecache.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/pxScene2d/test_imagecache.cpp b/tests/pxScene2d/test_imagecache.cpp index 6419761dad..df251ac3c7 100644 --- a/tests/pxScene2d/test_imagecache.cpp +++ b/tests/pxScene2d/test_imagecache.cpp @@ -26,10 +26,19 @@ #endif using namespace std; -bool failRealloc = false; bool defaultCallbackExecuted = false; extern void startFileDownloadInBackground(void* data); extern bool continueDownloadHandleCheck; + +// disabled as it causes crash +// please note that realloc is also extensively +// used by various glibc functions/threads +// also on linux even if the malloc/realloc returns non-null +// it doesn't guarantee that the returned memory will be available. +// #define UNAVAILABLE_MEMORY_TEST_ENABLED + +#ifdef UNAVAILABLE_MEMORY_TEST_ENABLED // { +bool failRealloc = false; typedef void* (*realloc_t)(void*, size_t); void* realloc(void *ptr, size_t size) @@ -48,6 +57,7 @@ void* realloc(void *ptr, size_t size) } return NULL; } +#endif // } UNAVAILABLE_MEMORY_TEST_ENABLED class commonTestFns { @@ -701,6 +711,7 @@ class rtHttpCacheTest : public testing::Test, public commonTestFns EXPECT_TRUE (RT_ERROR == data.data(contents)); } +#ifdef UNAVAILABLE_MEMORY_TEST_ENABLED // { void memoryUnAvailableTest() { rtString cacheHeader(""); @@ -716,7 +727,8 @@ class rtHttpCacheTest : public testing::Test, public commonTestFns EXPECT_TRUE (false == data.readFileData()); failRealloc = false; } - +#endif // } UNAVAILABLE_MEMORY_TEST_ENABLED + private: rtString defaultCacheHeader; }; @@ -753,7 +765,9 @@ TEST_F(rtHttpCacheTest, httpCacheCompleteTest) dataUpdatedAfterEtagTest(); */ dataUpdatedAfterEtagDownloadFailedTest(); +#ifdef UNAVAILABLE_MEMORY_TEST_ENABLED // { memoryUnAvailableTest(); +#endif // } UNAVAILABLE_MEMORY_TEST_ENABLED } class rtFileDownloaderTest : public testing::Test, public commonTestFns