summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-09 02:21:48 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-09 02:21:48 +0000
commit31cc2fdd5f43c4c6a0c0ebe0679458ecb3ba1593 (patch)
tree9419df0f203d66fc93dbbed6f400ea5a16ea5902 /third_party
parent84934a22839e7b16451ac37afc8b2b260d04edaa (diff)
downloadchromium_src-31cc2fdd5f43c4c6a0c0ebe0679458ecb3ba1593.zip
chromium_src-31cc2fdd5f43c4c6a0c0ebe0679458ecb3ba1593.tar.gz
chromium_src-31cc2fdd5f43c4c6a0c0ebe0679458ecb3ba1593.tar.bz2
Fix realloc to not call the new_handler (which is for failures)
when the request was for realloc(ptr, 0). Calling realloc(ptr, 0) is valid, and we should delete ptr and return NULL. BUG=none TEST=none Review URL: http://codereview.chromium.org/194040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25700 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r--third_party/tcmalloc/allocator_shim.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/third_party/tcmalloc/allocator_shim.cc b/third_party/tcmalloc/allocator_shim.cc
index 9877059..f5bc306 100644
--- a/third_party/tcmalloc/allocator_shim.cc
+++ b/third_party/tcmalloc/allocator_shim.cc
@@ -160,7 +160,11 @@ void* realloc(void* ptr, size_t size) __THROW {
// TCMalloc case.
new_ptr = do_realloc(ptr, size);
#endif
- if (new_ptr)
+
+ // Subtle warning: NULL return does not alwas indicate out-of-memory. If
+ // the requested new size is zero, realloc should free the ptr and return
+ // NULL.
+ if (new_ptr || !size)
return new_ptr;
if (!new_mode || !call_new_handler(true))
break;