Skip to content

Commit

Permalink
fix SIGSEGV caused by redefining realloc() (pxscene#896)
Browse files Browse the repository at this point in the history
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
 pxscene#1  0x00000000005af843 in realloc (ptr=0x0, size=32) at pxCore/tests/pxScene2d/test_imagecache.cpp:43
 pxscene#2  0x00007f070a988645 in pthread_getattr_np (thread_id=<optimized out>, attr=<optimized out>) at pthread_getattr_np.c:176
 pxscene#3  0x00007f070eeba185 in __sanitizer::GetThreadStackTopAndBottom(bool, unsigned long*, unsigned long*) () from /lib64/libtsan.so.0
 pxscene#4  0x00007f070eeba617 in __sanitizer::GetThreadStackAndTls(bool, unsigned long*, unsigned long*, unsigned long*, unsigned long*) () from /lib64/libtsan.so.0
 pxscene#5  0x00007f070eea8be6 in __tsan::ThreadStart(__tsan::ThreadState*, int, unsigned long) () from /lib64/libtsan.so.0
 pxscene#6  0x00007f070ee4b7d6 in __tsan_thread_start_func () from /lib64/libtsan.so.0
 pxscene#7  0x00007f070a98661b in start_thread (arg=0x7f0703aff700) at pthread_create.c:465
 pxscene#8  0x00007f07092db98f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  • Loading branch information
dwrobel authored and mfiess committed Feb 27, 2018
1 parent 77e75e2 commit 64ca7a5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tests/pxScene2d/test_imagecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -48,6 +57,7 @@ void* realloc(void *ptr, size_t size)
}
return NULL;
}
#endif // } UNAVAILABLE_MEMORY_TEST_ENABLED

class commonTestFns
{
Expand Down Expand Up @@ -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("");
Expand All @@ -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;
};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 64ca7a5

Please sign in to comment.