diff --git a/src/util-inl.h b/src/util-inl.h index 5ffe5b857f5381..82ab6632773854 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -357,39 +357,45 @@ T* UncheckedRealloc(T* pointer, size_t n) { // As per spec realloc behaves like malloc if passed nullptr. template -T* UncheckedMalloc(size_t n) { +inline T* UncheckedMalloc(size_t n) { if (n == 0) n = 1; return UncheckedRealloc(nullptr, n); } template -T* UncheckedCalloc(size_t n) { +inline T* UncheckedCalloc(size_t n) { if (n == 0) n = 1; MultiplyWithOverflowCheck(sizeof(T), n); return static_cast(calloc(n, sizeof(T))); } template -T* Realloc(T* pointer, size_t n) { +inline T* Realloc(T* pointer, size_t n) { T* ret = UncheckedRealloc(pointer, n); if (n > 0) CHECK_NE(ret, nullptr); return ret; } template -T* Malloc(size_t n) { +inline T* Malloc(size_t n) { T* ret = UncheckedMalloc(n); if (n > 0) CHECK_NE(ret, nullptr); return ret; } template -T* Calloc(size_t n) { +inline T* Calloc(size_t n) { T* ret = UncheckedCalloc(n); if (n > 0) CHECK_NE(ret, nullptr); return ret; } +// Shortcuts for char*. +inline char* Malloc(size_t n) { return Malloc(n); } +inline char* Calloc(size_t n) { return Calloc(n); } +inline char* UncheckedMalloc(size_t n) { return UncheckedMalloc(n); } +inline char* UncheckedCalloc(size_t n) { return UncheckedCalloc(n); } + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/util.h b/src/util.h index e2f9df02bc4361..3544870bc853a6 100644 --- a/src/util.h +++ b/src/util.h @@ -38,11 +38,10 @@ inline T* Malloc(size_t n); template inline T* Calloc(size_t n); -// Shortcuts for char*. -inline char* Malloc(size_t n) { return Malloc(n); } -inline char* Calloc(size_t n) { return Calloc(n); } -inline char* UncheckedMalloc(size_t n) { return UncheckedMalloc(n); } -inline char* UncheckedCalloc(size_t n) { return UncheckedCalloc(n); } +inline char* Malloc(size_t n); +inline char* Calloc(size_t n); +inline char* UncheckedMalloc(size_t n); +inline char* UncheckedCalloc(size_t n); // Used by the allocation functions when allocation fails. // Thin wrapper around v8::Isolate::LowMemoryNotification() that checks