| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4aec8cf commit 6a0eb9f
13 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -175,7 +175,7 @@ static void ares_poll_close_cb(uv_handle_t* watcher) { | |||
| 175 | 175 | ||
| 176 | 176 | /* Allocates and returns a new node_ares_task */ | |
| 177 | 177 | static node_ares_task* ares_task_create(Environment* env, ares_socket_t sock) { | |
| 178 | - auto task = node::Malloc<node_ares_task>(1); | ||
| 178 | + auto task = node::UncheckedMalloc<node_ares_task>(1); | ||
| 179 | 179 | ||
| 180 | 180 | if (task == nullptr) { | |
| 181 | 181 | /* Out of memory. */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1054,9 +1054,9 @@ void* ArrayBufferAllocator::Allocate(size_t size) { | |||
| 1054 | 1054 | if (env_ == nullptr || | |
| 1055 | 1055 | !env_->array_buffer_allocator_info()->no_zero_fill() || | |
| 1056 | 1056 | zero_fill_all_buffers) | |
| 1057 | - return node::Calloc(size); | ||
| 1057 | + return node::UncheckedCalloc(size); | ||
| 1058 | 1058 | env_->array_buffer_allocator_info()->reset_fill_flag(); | |
| 1059 | - return node::Malloc(size); | ||
| 1059 | + return node::UncheckedMalloc(size); | ||
| 1060 | 1060 | } | |
| 1061 | 1061 | ||
| 1062 | 1062 | static bool DomainHasErrorHandler(const Environment* env, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,8 +56,8 @@ bool zero_fill_all_buffers = false; | |||
| 56 | 56 | namespace { | |
| 57 | 57 | ||
| 58 | 58 | inline void* BufferMalloc(size_t length) { | |
| 59 | - return zero_fill_all_buffers ? node::Calloc(length) : | ||
| 60 | - node::Malloc(length); | ||
| 59 | + return zero_fill_all_buffers ? node::UncheckedCalloc(length) : | ||
| 60 | + node::UncheckedMalloc(length); | ||
| 61 | 61 | } | |
| 62 | 62 | ||
| 63 | 63 | } // namespace | |
@@ -253,7 +253,6 @@ MaybeLocal<Object> New(Isolate* isolate, | |||
| 253 | 253 | data = nullptr; | |
| 254 | 254 | } else if (actual < length) { | |
| 255 | 255 | data = node::Realloc(data, actual); | |
| 256 | - CHECK_NE(data, nullptr); | ||
| 257 | 256 | } | |
| 258 | 257 | } | |
| 259 | 258 | ||
@@ -331,7 +330,7 @@ MaybeLocal<Object> Copy(Environment* env, const char* data, size_t length) { | |||
| 331 | 330 | void* new_data; | |
| 332 | 331 | if (length > 0) { | |
| 333 | 332 | CHECK_NE(data, nullptr); | |
| 334 | - new_data = node::Malloc(length); | ||
| 333 | + new_data = node::UncheckedMalloc(length); | ||
| 335 | 334 | if (new_data == nullptr) | |
| 336 | 335 | return Local<Object>(); | |
| 337 | 336 | memcpy(new_data, data, length); | |
@@ -1069,7 +1068,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | |||
| 1069 | 1068 | offset, | |
| 1070 | 1069 | is_forward); | |
| 1071 | 1070 | } else if (enc == LATIN1) { | |
| 1072 | - uint8_t* needle_data = node::Malloc<uint8_t>(needle_length); | ||
| 1071 | + uint8_t* needle_data = node::UncheckedMalloc<uint8_t>(needle_length); | ||
| 1073 | 1072 | if (needle_data == nullptr) { | |
| 1074 | 1073 | return args.GetReturnValue().Set(-1); | |
| 1075 | 1074 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2387,7 +2387,6 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) { | |||
| 2387 | 2387 | ||
| 2388 | 2388 | // OpenSSL takes control of the pointer after accepting it | |
| 2389 | 2389 | char* data = node::Malloc(len); | |
| 2390 | - CHECK_NE(data, nullptr); | ||
| 2391 | 2390 | memcpy(data, resp, len); | |
| 2392 | 2391 | ||
| 2393 | 2392 | if (!SSL_set_tlsext_status_ocsp_resp(s, data, len)) | |
@@ -3467,7 +3466,6 @@ bool CipherBase::GetAuthTag(char** out, unsigned int* out_len) const { | |||
| 3467 | 3466 | return false; | |
| 3468 | 3467 | *out_len = auth_tag_len_; | |
| 3469 | 3468 | *out = node::Malloc(auth_tag_len_); | |
| 3470 | - CHECK_NE(*out, nullptr); | ||
| 3471 | 3469 | memcpy(*out, auth_tag_, auth_tag_len_); | |
| 3472 | 3470 | return true; | |
| 3473 | 3471 | } | |
@@ -5139,7 +5137,6 @@ void ECDH::ComputeSecret(const FunctionCallbackInfo<Value>& args) { | |||
| 5139 | 5137 | int field_size = EC_GROUP_get_degree(ecdh->group_); | |
| 5140 | 5138 | size_t out_len = (field_size + 7) / 8; | |
| 5141 | 5139 | char* out = node::Malloc(out_len); | |
| 5142 | - CHECK_NE(out, nullptr); | ||
| 5143 | 5140 | ||
| 5144 | 5141 | int r = ECDH_compute_key(out, out_len, pub, ecdh->key_, nullptr); | |
| 5145 | 5142 | EC_POINT_free(pub); | |
@@ -5175,7 +5172,6 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) { | |||
| 5175 | 5172 | return env->ThrowError("Failed to get public key length"); | |
| 5176 | 5173 | ||
| 5177 | 5174 | unsigned char* out = node::Malloc<unsigned char>(size); | |
| 5178 | - CHECK_NE(out, nullptr); | ||
| 5179 | 5175 | ||
| 5180 | 5176 | int r = EC_POINT_point2oct(ecdh->group_, pub, form, out, size, nullptr); | |
| 5181 | 5177 | if (r != size) { | |
@@ -5201,7 +5197,6 @@ void ECDH::GetPrivateKey(const FunctionCallbackInfo<Value>& args) { | |||
| 5201 | 5197 | ||
| 5202 | 5198 | int size = BN_num_bytes(b); | |
| 5203 | 5199 | unsigned char* out = node::Malloc<unsigned char>(size); | |
| 5204 | - CHECK_NE(out, nullptr); | ||
| 5205 | 5200 | ||
| 5206 | 5201 | if (size != BN_bn2bin(b, out)) { | |
| 5207 | 5202 | free(out); | |
@@ -5335,8 +5330,6 @@ class PBKDF2Request : public AsyncWrap { | |||
| 5335 | 5330 | keylen_(keylen), | |
| 5336 | 5331 | key_(node::Malloc(keylen)), | |
| 5337 | 5332 | iter_(iter) { | |
| 5338 | - if (key() == nullptr) | ||
| 5339 | - FatalError("node::PBKDF2Request()", "Out of Memory"); | ||
| 5340 | 5333 | Wrap(object, this); | |
| 5341 | 5334 | } | |
| 5342 | 5335 | ||
@@ -5497,9 +5490,6 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { | |||
| 5497 | 5490 | THROW_AND_RETURN_IF_NOT_BUFFER(args[1], "Salt"); | |
| 5498 | 5491 | ||
| 5499 | 5492 | pass = node::Malloc(passlen); | |
| 5500 | - if (pass == nullptr) { | ||
| 5501 | - FatalError("node::PBKDF2()", "Out of Memory"); | ||
| 5502 | - } | ||
| 5503 | 5493 | memcpy(pass, Buffer::Data(args[0]), passlen); | |
| 5504 | 5494 | ||
| 5505 | 5495 | saltlen = Buffer::Length(args[1]); | |
@@ -5509,9 +5499,6 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { | |||
| 5509 | 5499 | } | |
| 5510 | 5500 | ||
| 5511 | 5501 | salt = node::Malloc(saltlen); | |
| 5512 | - if (salt == nullptr) { | ||
| 5513 | - FatalError("node::PBKDF2()", "Out of Memory"); | ||
| 5514 | - } | ||
| 5515 | 5502 | memcpy(salt, Buffer::Data(args[1]), saltlen); | |
| 5516 | 5503 | ||
| 5517 | 5504 | if (!args[2]->IsNumber()) { | |
@@ -5602,8 +5589,6 @@ class RandomBytesRequest : public AsyncWrap { | |||
| 5602 | 5589 | error_(0), | |
| 5603 | 5590 | size_(size), | |
| 5604 | 5591 | data_(node::Malloc(size)) { | |
| 5605 | - if (data() == nullptr) | ||
| 5606 | - FatalError("node::RandomBytesRequest()", "Out of Memory"); | ||
| 5607 | 5592 | Wrap(object, this); | |
| 5608 | 5593 | } | |
| 5609 | 5594 | ||
@@ -5830,8 +5815,6 @@ void GetCurves(const FunctionCallbackInfo<Value>& args) { | |||
| 5830 | 5815 | if (num_curves) { | |
| 5831 | 5816 | curves = node::Malloc<EC_builtin_curve>(num_curves); | |
| 5832 | 5817 | ||
| 5833 | - CHECK_NE(curves, nullptr); | ||
| 5834 | - | ||
| 5835 | 5818 | if (EC_get_builtin_curves(curves, num_curves)) { | |
| 5836 | 5819 | for (size_t i = 0; i < num_curves; i++) { | |
| 5837 | 5820 | arr->Set(i, OneByteString(env->isolate(), OBJ_nid2sn(curves[i].nid))); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -199,7 +199,7 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | |||
| 199 | 199 | ||
| 200 | 200 | virtual void* Allocate(size_t size); // Defined in src/node.cc | |
| 201 | 201 | virtual void* AllocateUninitialized(size_t size) | |
| 202 | - { return node::Malloc(size); } | ||
| 202 | + { return node::UncheckedMalloc(size); } | ||
| 203 | 203 | virtual void Free(void* data, size_t) { free(data); } | |
| 204 | 204 | ||
| 205 | 205 | private: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -150,12 +150,6 @@ void StreamWrap::OnAlloc(uv_handle_t* handle, | |||
| 150 | 150 | void StreamWrap::OnAllocImpl(size_t size, uv_buf_t* buf, void* ctx) { | |
| 151 | 151 | buf->base = node::Malloc(size); | |
| 152 | 152 | buf->len = size; | |
| 153 | - | ||
| 154 | - if (buf->base == nullptr && size > 0) { | ||
| 155 | - FatalError( | ||
| 156 | - "node::StreamWrap::DoAlloc(size_t, uv_buf_t*, void*)", | ||
| 157 | - "Out Of Memory"); | ||
| 158 | - } | ||
| 159 | 153 | } | |
| 160 | 154 | ||
| 161 | 155 | ||
@@ -204,8 +198,8 @@ void StreamWrap::OnReadImpl(ssize_t nread, | |||
| 204 | 198 | return; | |
| 205 | 199 | } | |
| 206 | 200 | ||
| 207 | - char* base = node::Realloc(buf->base, nread); | ||
| 208 | 201 | CHECK_LE(static_cast<size_t>(nread), buf->len); | |
| 202 | + char* base = node::Realloc(buf->base, nread); | ||
| 209 | 203 | ||
| 210 | 204 | if (pending == UV_TCP) { | |
| 211 | 205 | pending_obj = AcceptHandle<TCPWrap, uv_tcp_t>(env, wrap); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,7 +53,7 @@ class ExternString: public ResourceType { | |||
| 53 | 53 | if (length == 0) | |
| 54 | 54 | return scope.Escape(String::Empty(isolate)); | |
| 55 | 55 | ||
| 56 | - TypeName* new_data = node::Malloc<TypeName>(length); | ||
| 56 | + TypeName* new_data = node::UncheckedMalloc<TypeName>(length); | ||
| 57 | 57 | if (new_data == nullptr) { | |
| 58 | 58 | return Local<String>(); | |
| 59 | 59 | } | |
@@ -609,7 +609,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate, | |||
| 609 | 609 | ||
| 610 | 610 | case ASCII: | |
| 611 | 611 | if (contains_non_ascii(buf, buflen)) { | |
| 612 | - char* out = node::Malloc(buflen); | ||
| 612 | + char* out = node::UncheckedMalloc(buflen); | ||
| 613 | 613 | if (out == nullptr) { | |
| 614 | 614 | return Local<String>(); | |
| 615 | 615 | } | |
@@ -644,7 +644,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate, | |||
| 644 | 644 | ||
| 645 | 645 | case BASE64: { | |
| 646 | 646 | size_t dlen = base64_encoded_size(buflen); | |
| 647 | - char* dst = node::Malloc(dlen); | ||
| 647 | + char* dst = node::UncheckedMalloc(dlen); | ||
| 648 | 648 | if (dst == nullptr) { | |
| 649 | 649 | return Local<String>(); | |
| 650 | 650 | } | |
@@ -663,7 +663,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate, | |||
| 663 | 663 | ||
| 664 | 664 | case HEX: { | |
| 665 | 665 | size_t dlen = buflen * 2; | |
| 666 | - char* dst = node::Malloc(dlen); | ||
| 666 | + char* dst = node::UncheckedMalloc(dlen); | ||
| 667 | 667 | if (dst == nullptr) { | |
| 668 | 668 | return Local<String>(); | |
| 669 | 669 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -664,7 +664,6 @@ void TLSWrap::OnDestructImpl(void* ctx) { | |||
| 664 | 664 | ||
| 665 | 665 | void TLSWrap::OnAllocSelf(size_t suggested_size, uv_buf_t* buf, void* ctx) { | |
| 666 | 666 | buf->base = node::Malloc(suggested_size); | |
| 667 | - CHECK_NE(buf->base, nullptr); | ||
| 668 | 667 | buf->len = suggested_size; | |
| 669 | 668 | } | |
| 670 | 669 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -375,11 +375,6 @@ void UDPWrap::OnAlloc(uv_handle_t* handle, | |||
| 375 | 375 | uv_buf_t* buf) { | |
| 376 | 376 | buf->base = node::Malloc(suggested_size); | |
| 377 | 377 | buf->len = suggested_size; | |
| 378 | - | ||
| 379 | - if (buf->base == nullptr && suggested_size > 0) { | ||
| 380 | - FatalError("node::UDPWrap::OnAlloc(uv_handle_t*, size_t, uv_buf_t*)", | ||
| 381 | - "Out Of Memory"); | ||
| 382 | - } | ||
| 383 | 378 | } | |
| 384 | 379 | ||
| 385 | 380 | ||
@@ -415,7 +410,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, | |||
| 415 | 410 | return; | |
| 416 | 411 | } | |
| 417 | 412 | ||
| 418 | - char* base = node::Realloc(buf->base, nread); | ||
| 413 | + char* base = node::UncheckedRealloc(buf->base, nread); | ||
| 419 | 414 | argv[2] = Buffer::New(env, base, nread).ToLocalChecked(); | |
| 420 | 415 | argv[3] = AddressToJS(env, addr); | |
| 421 | 416 | wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -336,7 +336,7 @@ inline size_t MultiplyWithOverflowCheck(size_t a, size_t b) { | |||
| 336 | 336 | // nullptr for zero-sized allocation requests. Normalize by always using | |
| 337 | 337 | // a nullptr. | |
| 338 | 338 | template <typename T> | |
| 339 | - T* Realloc(T* pointer, size_t n) { | ||
| 339 | + T* UncheckedRealloc(T* pointer, size_t n) { | ||
| 340 | 340 | size_t full_size = MultiplyWithOverflowCheck(sizeof(T), n); | |
| 341 | 341 | ||
| 342 | 342 | if (full_size == 0) { | |
@@ -349,18 +349,39 @@ T* Realloc(T* pointer, size_t n) { | |||
| 349 | 349 | ||
| 350 | 350 | // As per spec realloc behaves like malloc if passed nullptr. | |
| 351 | 351 | template <typename T> | |
| 352 | - T* Malloc(size_t n) { | ||
| 352 | + T* UncheckedMalloc(size_t n) { | ||
| 353 | 353 | if (n == 0) n = 1; | |
| 354 | - return Realloc<T>(nullptr, n); | ||
| 354 | + return UncheckedRealloc<T>(nullptr, n); | ||
| 355 | 355 | } | |
| 356 | 356 | ||
| 357 | 357 | template <typename T> | |
| 358 | - T* Calloc(size_t n) { | ||
| 358 | + T* UncheckedCalloc(size_t n) { | ||
| 359 | 359 | if (n == 0) n = 1; | |
| 360 | 360 | MultiplyWithOverflowCheck(sizeof(T), n); | |
| 361 | 361 | return static_cast<T*>(calloc(n, sizeof(T))); | |
| 362 | 362 | } | |
| 363 | 363 | ||
| 364 | + template <typename T> | ||
| 365 | + T* Realloc(T* pointer, size_t n) { | ||
| 366 | + T* ret = UncheckedRealloc(pointer, n); | ||
| 367 | + if (n > 0) CHECK_NE(ret, nullptr); | ||
| 368 | + return ret; | ||
| 369 | + } | ||
| 370 | + | ||
| 371 | + template <typename T> | ||
| 372 | + T* Malloc(size_t n) { | ||
| 373 | + T* ret = UncheckedMalloc<T>(n); | ||
| 374 | + if (n > 0) CHECK_NE(ret, nullptr); | ||
| 375 | + return ret; | ||
| 376 | + } | ||
| 377 | + | ||
| 378 | + template <typename T> | ||
| 379 | + T* Calloc(size_t n) { | ||
| 380 | + T* ret = UncheckedCalloc<T>(n); | ||
| 381 | + if (n > 0) CHECK_NE(ret, nullptr); | ||
| 382 | + return ret; | ||
| 383 | + } | ||
| 384 | + | ||
| 364 | 385 | } // namespace node | |
| 365 | 386 | ||
| 366 | 387 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| Back | FazBrowse Home | New Git URL |
0 commit comments