Skip to content

Commit

Permalink
wrap strdup in macos to detect leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
pako-23 committed Sep 11, 2024
1 parent 0c56383 commit 1f8987c
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 77 deletions.
10 changes: 9 additions & 1 deletion basic_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,20 @@ void * reallocf (void * ptr, size_t size) {
static void *(*libc_reallocf)(void *, size_t) = NULL;

if (!libc_reallocf)
libc_reallocf = (void *(*)(size_t, size_t)) dlsym(RTLD_NEXT, "reallocf");
libc_reallocf = (void *(*)(void *, size_t)) dlsym(RTLD_NEXT, "reallocf");

void * ret = realloc (ptr, size);
if (!ret) free (ptr);
return ret;
}

BT_POSSIBLY_UNUSED
char * strdup (const char * s) {
size_t len = strlen (s);
char * ret = (char *) malloc (len + 1);
if (ret) strcpy (ret, s);
return ret;
}
#endif

#ifndef __APPLE__
Expand Down
8 changes: 0 additions & 8 deletions ex/memory_checks.expected
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,9 @@ Running test 05_byte_budget_allocations_debug... PASS
Running test 06_scheduled_failures... PASS
Running test 06_scheduled_failures_debug... PASS
Running test 07_calloc_reallocarray_failures... PASS
Running test 08_fopen_leak...
FAIL
run 'tests/08_fopen_leak' to see what went wrong
run 'tests/08_fopen_leak -d' with a debugger
Running test 08_stdlib_functions... PASS
Running test 08_strdup_leak...
leaked 8 bytes
FAIL
run 'tests/08_strdup_leak' to see what went wrong
run 'tests/08_strdup_leak -d' with a debugger
Running test 08_tmpfile_leak...
FAIL
run 'tests/08_tmpfile_leak' to see what went wrong
run 'tests/08_tmpfile_leak -d' with a debugger
15 changes: 0 additions & 15 deletions ex/memory_checks/tests/08_fopen_leak.c

This file was deleted.

15 changes: 0 additions & 15 deletions ex/memory_checks/tests/08_tmpfile_leak.c

This file was deleted.

8 changes: 0 additions & 8 deletions ex/memory_checks_cpp.expected
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,9 @@ Running test 05_byte_budget_allocations_debug... PASS
Running test 06_scheduled_failures... PASS
Running test 06_scheduled_failures_debug... PASS
Running test 07_calloc_reallocarray_failures... PASS
Running test 08_fopen_leak...
FAIL
run 'tests/08_fopen_leak' to see what went wrong
run 'tests/08_fopen_leak -d' with a debugger
Running test 08_stdlib_functions... PASS
Running test 08_strdup_leak...
leaked 8 bytes
FAIL
run 'tests/08_strdup_leak' to see what went wrong
run 'tests/08_strdup_leak -d' with a debugger
Running test 08_tmpfile_leak...
FAIL
run 'tests/08_tmpfile_leak' to see what went wrong
run 'tests/08_tmpfile_leak -d' with a debugger
15 changes: 0 additions & 15 deletions ex/memory_checks_cpp/tests/08_fopen_leak.cc

This file was deleted.

15 changes: 0 additions & 15 deletions ex/memory_checks_cpp/tests/08_tmpfile_leak.cc

This file was deleted.

0 comments on commit 1f8987c

Please sign in to comment.