facebook / facebook/rocksdb

Do not call malloc_usable_size on memory allocated with new[]

Open
#10,798 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
32.1k
Forks
6.9k
Avg merge
32m
Merged PRs (30d)
1

Description

It is only legal to call `malloc_usable_size()` on memory allocated with `malloc` or `calloc` (or `realloc` etc), not C++ `new` and `new[]`; this matters, especially with C++14 when using sized `operator delete`.

If `allocator` is unset, we allocate using `new[]`: https://github.com/facebook/rocksdb/blob/fac7a31c95de8047f0eeb4e3cd35108d0ba0f821/memory/memory_allocator.h#L35

and then call `malloc_usable_size()` on that pointer: https://github.com/facebook/rocksdb/blob/fac7a31c95de8047f0eeb4e3cd35108d0ba0f821/table/format.h#L316

The fix would be to either change `AllocateBlock` to allocate using `malloc` when the allocator is unset (and change the corresponding deleter to use `free`!) or to remove the `#ifdef` branch that uses `malloc_usable_size()` in `format.h` altogether.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.