Commit 7c2d39a1 authored by Andre Pinto's avatar Andre Pinto Committed by Facebook Github Bot

Fix IOBuf::createCombined()

Summary:
IOBuf::createCombined was derefencing a nullptr in case of allocation failure.
This patches fixes this issue by throwing std::bad_alloc if malloc() returns a
nullptr.

Reviewed By: yfeldblum

Differential Revision: D9763331

fbshipit-source-id: 7d9b9265079e74f5c63c8c8809099de97342f54d
parent 875449cd
......@@ -245,7 +245,7 @@ unique_ptr<IOBuf> IOBuf::createCombined(std::size_t capacity) {
// SharedInfo struct, and the data itself all with a single call to malloc().
size_t requiredStorage = offsetof(HeapFullStorage, align) + capacity;
size_t mallocSize = goodMallocSize(requiredStorage);
auto* storage = static_cast<HeapFullStorage*>(malloc(mallocSize));
auto* storage = static_cast<HeapFullStorage*>(checkedMalloc(mallocSize));
new (&storage->hs.prefix) HeapPrefix(kIOBufInUse | kDataInUse);
new (&storage->shared) SharedInfo(freeInternalBuf, storage);
......
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