summaryrefslogtreecommitdiff
path: root/lib/tsan
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2016-08-02 14:22:12 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2016-08-02 14:22:12 +0000
commita602a6d33501a813770698a7150b4113a430af47 (patch)
treed1994f82431ed89ec006a8c919e20c529111745e /lib/tsan
parent15712ac4dd8fa2f605ae1bebab233694b3d62383 (diff)
[tsan] Fix behavior of realloc(nullptr, 0) on Darwin
On Darwin, there are some apps that rely on realloc(nullptr, 0) returning a valid pointer. TSan currently returns nullptr in this case, let's fix it to avoid breaking binary compatibility. Differential Revision: https://reviews.llvm.org/D22800 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277458 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/tsan')
-rw-r--r--lib/tsan/rtl/tsan_mman.cc18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/tsan/rtl/tsan_mman.cc b/lib/tsan/rtl/tsan_mman.cc
index 7693077f6..f99ddb35b 100644
--- a/lib/tsan/rtl/tsan_mman.cc
+++ b/lib/tsan/rtl/tsan_mman.cc
@@ -195,20 +195,16 @@ void OnUserFree(ThreadState *thr, uptr pc, uptr p, bool write) {
}
void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz) {
- void *p2 = 0;
// FIXME: Handle "shrinking" more efficiently,
// it seems that some software actually does this.
- if (sz) {
- p2 = user_alloc(thr, pc, sz);
- if (p2 == 0)
- return 0;
- if (p) {
- uptr oldsz = user_alloc_usable_size(p);
- internal_memcpy(p2, p, min(oldsz, sz));
- }
- }
- if (p)
+ void *p2 = user_alloc(thr, pc, sz);
+ if (p2 == 0)
+ return 0;
+ if (p) {
+ uptr oldsz = user_alloc_usable_size(p);
+ internal_memcpy(p2, p, min(oldsz, sz));
user_free(thr, pc, p);
+ }
return p2;
}