diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-04-10 10:53:54 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-04-14 23:06:48 +0200 |
commit | 427fce711f864f206a52ee8883442d443a8c4d34 (patch) | |
tree | 5a98023ffa9833b43caeae25cabd35da1b750d26 /src/api | |
parent | d4e743169eac7680dbbb67b11c6362fb15ca5f9a (diff) | |
download | android-node-v8-427fce711f864f206a52ee8883442d443a8c4d34.tar.gz android-node-v8-427fce711f864f206a52ee8883442d443a8c4d34.tar.bz2 android-node-v8-427fce711f864f206a52ee8883442d443a8c4d34.zip |
src: fix check for accepting Buffers into Node’s allocator
This condition was incorrect. We currently take the fallback
path in default Node builds, which always works, but may come with
some overhead, whereas the intention was that we use the fast path
in this condition.
This is causing issues for embedders, because we would erroneously
try to take the fast path when they don’t provide a Node.js-style
`ArrayBufferAlloactor`, and crash as a consequence of that.
This also requires us to relax the check in the debugging ArrayBuffer
allocator a bit, because since d117e41e50667d7a36, 0-sized ArrayBuffers
may actually point to allocations of size 1. Previously, that wasn’t
caught because the fallback path circumvented our ArrayBufferAllocator.
Refs: https://github.com/nodejs/node/commit/84e02b178ad14fae0df2a514e8a39bfa50ffdc2d#r33116006
PR-URL: https://github.com/nodejs/node/pull/27174
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/environment.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/api/environment.cc b/src/api/environment.cc index a87f591e4e..70228b77d8 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -139,7 +139,11 @@ void DebuggingArrayBufferAllocator::UnregisterPointerInternal(void* data, if (data == nullptr) return; auto it = allocations_.find(data); CHECK_NE(it, allocations_.end()); - CHECK_EQ(it->second, size); + if (size > 0) { + // We allow allocations with size 1 for 0-length buffers to avoid having + // to deal with nullptr values. + CHECK_EQ(it->second, size); + } allocations_.erase(it); } |