From 9d2229f3caad26c9b5758cd06a629aaa7f8ab96b Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 21 May 2012 06:46:27 +0000 Subject: [PATCH] tsan: add more checks for OOM conditions tests like to try to malloc((size_t)-1) llvm-svn: 157176 --- compiler-rt/lib/tsan/rtl/tsan_mman.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cc b/compiler-rt/lib/tsan/rtl/tsan_mman.cc index 5ffd603..afa5763 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_mman.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cc @@ -33,6 +33,8 @@ void *user_alloc(ThreadState *thr, uptr pc, uptr sz) { if (sz + sizeof(MBlock) < sz) return 0; MBlock *b = (MBlock*)Alloc(sz + sizeof(MBlock)); + if (b == 0) + return 0; b->size = sz; void *p = b + 1; if (CTX() && CTX()->initialized) { @@ -63,6 +65,8 @@ void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz) { // it seems that some software actually does this. if (sz) { p2 = user_alloc(thr, pc, sz); + if (p2 == 0) + return 0; if (p) { MBlock *b = user_mblock(thr, p); internal_memcpy(p2, p, min(b->size, sz)); -- 2.7.4