Commit a97abdc1 authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

safer behavior for goodMallocSize on very large minSize

Summary:
Currently malloc(goodMallocSize(x)) will succeed when x is larger
than the maximum possible allocation supported by jemalloc.  This is
not desirable.  Currently goodMallocSize(x) returns 0 if x is too large,
but 0 is a valid argument for malloc and causes a 1 byte allocation.
This diff causes goodMallocSize(x) to return x in that case, which will
cause the subsequent malloc to fail.  The caller may catch that failure
or crash immediately, but those are both preferrable to returning a
pointer to a valid 1-byte allocation.

Reviewed By: al13n321

Differential Revision: D9778137

fbshipit-source-id: 3eb8da72d6240b28da85483f0d91653f5e04b333
parent e2be2a4a
......@@ -208,7 +208,10 @@ inline size_t goodMallocSize(size_t minSize) noexcept {
return minSize;
}
return nallocx(minSize, 0);
// nallocx returns 0 if minSize can't succeed, but 0 is not actually
// a goodMallocSize if you want minSize
auto rv = nallocx(minSize, 0);
return rv ? rv : minSize;
}
// We always request "good" sizes for allocation, so jemalloc can
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment