apache / apache/nuttx

Size requested from sbrk is not the actual size needed.

Open
#9,155 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
4k
Forks
1.7k
Avg merge
1d 17h
Merged PRs (30d)
237

Description

Originally, there was logic like the following for KERNEL mode in `mm/mm_heap/`:

brkaddr = sbrk(size);

When we modified this to handle the case of size == 0, this became:

brkaddr = sbrk(size < 1 ? 1 : size);

But there still could be an issue here. Not just for `size < 1` for for all sizes. The sizes don't include quantization overhead, or the overhead from the memory header. So the amount of memory requested is smaller than that which is actually needed. If nothing else, that does leave me a little uneasy.

I am thinking it should be like:

chunksize = size < MM_MIN_CHUNK ? (size + (MM_MIN_CHUNK - 1)) % MM_MIN_CHUNK
brkaddr = sbrk(chunksize);

But I have not looked at the detailed logic in `sbrk` to see how it handles the size. Perhaps there is no problem. This issue is simply to verify that that is the case.

As has been pointed out `MM_MIN_CHUNK `is not valid for `tlsf_realloc()`. But even if `tlsf_realloc() `and `mm_realloc()` are different in this way, that would not change the issue, that would just make any solution that might be needed more difficult (and I'm not even certain that any solution is needed).

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.