src: better error message on failed Buffer malloc

PR-URL: https://github.com/nodejs/node/pull/2422
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
pull/2415/merge
Karl Skomski 2015-08-17 22:51:42 +02:00 committed by Ben Noordhuis
parent 00bffa6c75
commit 90a2671889
1 changed files with 4 additions and 2 deletions

View File

@ -408,8 +408,10 @@ void Create(const FunctionCallbackInfo<Value>& args) {
void* data;
if (length > 0) {
data = malloc(length);
if (data == nullptr)
return env->ThrowRangeError("invalid Buffer length");
if (data == nullptr) {
return env->ThrowRangeError(
"Buffer allocation failed - process out of memory");
}
} else {
data = nullptr;
}