Skip to content

Commit

Permalink
Merge pull request #135 from palainp/fix-posixmemalign
Browse files Browse the repository at this point in the history
fix memory usage for posix_memalign
  • Loading branch information
hannesm committed Apr 23, 2024
2 parents 96515bc + fdae07c commit b1bd828
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nolibc/dlmalloc.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
memory allocated in the heap.
The results of this fast estimation are returned by the
dlmalloc_memory_usage function exported as malloc_memory_usage.
See lines 993, 2629 and in dlmalloc(), dlfree() and dlrealloc*()
See lines 993, 2629 and in dlmalloc(), dlfree(), internal_memalign()
and dlrealloc*()
*/

/*
Expand Down Expand Up @@ -4942,6 +4943,7 @@ static void* internal_memalign(mstate m, size_t alignment, size_t bytes) {
mem = internal_malloc(m, req);
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
size_t prevsize = chunksize(p);
if (PREACTION(m))
return 0;
if ((((size_t)(mem)) & (alignment - 1)) != 0) { /* misaligned */
Expand Down Expand Up @@ -4990,6 +4992,8 @@ static void* internal_memalign(mstate m, size_t alignment, size_t bytes) {
assert (chunksize(p) >= nb);
assert(((size_t)mem & (alignment - 1)) == 0);
check_inuse_chunk(m, p);
/* internal_malloc has been called, but the allocated block might be reduced, so manually update internal_memory_usage */
gm->internal_memory_usage += chunksize(p) - prevsize;
POSTACTION(m);
}
}
Expand Down

0 comments on commit b1bd828

Please sign in to comment.