Skip to content

Commit

Permalink
Redirect malloc_usable_size() in leak_detector.h
Browse files Browse the repository at this point in the history
(a cherry-pick of commit b54d7cc from 'master')

PR #645 (bdwgc).

* include/leak_detector.h (malloc_usable_size): Redefine macro (to
GC_size).
* tests/leak_test.c (main): Call malloc_usable_size().
  • Loading branch information
Fabian Ruffy authored and ivmai committed Sep 1, 2024
1 parent b1736bd commit 6110f34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/leak_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
#undef posix_memalign
#define posix_memalign(p,a,n) GC_posix_memalign(p,a,n)

#undef malloc_usable_size
#define malloc_usable_size(p) GC_size(p)

#ifndef CHECK_LEAKS
# define CHECK_LEAKS() GC_gcollect()
/* Note 1: CHECK_LEAKS does not have GC prefix (preserved for */
Expand Down
1 change: 1 addition & 0 deletions tests/leak_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int main(void) {
for (i = 0; i < 10; ++i) {
p[i] = (char*)malloc(sizeof(int)+i);
CHECK_OUT_OF_MEMORY(p[i]);
(void)malloc_usable_size(p[i]);
}
CHECK_LEAKS();
for (i = 1; i < 10; ++i) {
Expand Down

0 comments on commit 6110f34

Please sign in to comment.