diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2014-03-14 23:22:27 +0100 |
---|---|---|
committer | Fedor Indutny <fedor.indutny@gmail.com> | 2014-03-16 16:15:33 +0400 |
commit | f6ea0c203aa08c4817c7739461f8e7015d390279 (patch) | |
tree | e6d9bd5a5af9c1be9ae3f92bf71734ff3f08f1a0 /src/node_zlib.cc | |
parent | a3dca9a3a6876e792509cbe47d7210eb4bdb114a (diff) | |
download | node-new-f6ea0c203aa08c4817c7739461f8e7015d390279.tar.gz |
src: fix segfaults, fix 32 bits integer negation
Make calls to v8::Isolate::AdjustAmountOfExternalAllocatedMemory() take
special care when negating 32 bits unsigned types like size_t.
Before this commit, values were negated before they got promoted to
64 bits, meaning that on 32 bits architectures, a value like 42 got
cast to 4294967254 instead of -42.
That in turn made the garbage collector start scavenging like crazy
because it thought the system was out of memory.
That's bad enough but calls to AdjustAmountOfExternalAllocatedMemory()
were made from weak callbacks, i.e. at a time when the garbage collector
was already busy. It triggered asserts in debug builds and caused
random crashes and memory corruption in release builds.
The behavior in release builds is arguably a V8 bug and should perhaps
be reported upstream.
Partially fixes #7309 but requires further bug fixes to src/smalloc.cc
that I'll address in a follow-up commit.
Diffstat (limited to 'src/node_zlib.cc')
-rw-r--r-- | src/node_zlib.cc | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 81d98d17c9..08a20ca553 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -110,13 +110,13 @@ class ZCtx : public AsyncWrap { if (mode_ == DEFLATE || mode_ == GZIP || mode_ == DEFLATERAW) { (void)deflateEnd(&strm_); - env()->isolate() - ->AdjustAmountOfExternalAllocatedMemory(-kDeflateContextSize); + int64_t change_in_bytes = -static_cast<int64_t>(kDeflateContextSize); + env()->isolate()->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); } else if (mode_ == INFLATE || mode_ == GUNZIP || mode_ == INFLATERAW || mode_ == UNZIP) { (void)inflateEnd(&strm_); - env()->isolate() - ->AdjustAmountOfExternalAllocatedMemory(-kInflateContextSize); + int64_t change_in_bytes = -static_cast<int64_t>(kInflateContextSize); + env()->isolate()->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); } mode_ = NONE; |