Skip to content

Commit

Permalink
Use debug version of malloc when ASSERTIONS=1. NFC
Browse files Browse the repository at this point in the history
Previously we were only using it with `ASSERTIONS=2`.  The debug version
dlmalloc has a lot very useful checks.  Enabling this found a few real
issues in our test code.
  • Loading branch information
sbc100 committed Jan 8, 2025
1 parent 7bc099c commit 69bcd90
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'libemmalloc-memvalidate-verbose',
'libmimalloc',
'libmimalloc-mt',
'libmimalloc-mt-debug',
'libGL',
'libGL-getprocaddr',
'libGL-emu-getprocaddr',
Expand Down Expand Up @@ -101,6 +102,7 @@
'libc++-mt',
'libc++-mt-noexcept',
'libdlmalloc-mt',
'libdlmalloc-mt-debug',
'libGL-emu',
'libGL-emu-webgl2-getprocaddr',
'libGL-mt-getprocaddr',
Expand Down
8 changes: 6 additions & 2 deletions test/other/test_tsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ static void action(const void *nodep, VISIT which, int depth) {
}
}

static void free_node(void* nodep) {
// no-op since we didn't allocate any per-node data
}

int main(void) {
int ptr[12];
void *val = NULL;
Expand All @@ -51,6 +55,6 @@ int main(void) {
assert(val);
}
twalk(root, action);
tdestroy(root, free);
tdestroy(root, free_node);
return 0;
}
}
6 changes: 3 additions & 3 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7951,10 +7951,10 @@ def test_dlmalloc_modes(self):
printf("double-freed\n");
}
''')
self.run_process([EMCC, 'src.c'])
self.run_process([EMCC, 'src.c', '-O2'])
self.assertContained('double-freed', self.run_js('a.out.js'))
# in debug mode, the double-free is caught
self.run_process([EMCC, 'src.c', '-sASSERTIONS=2'])
self.run_process([EMCC, 'src.c', '-O0'])
out = self.run_js('a.out.js', assert_returncode=NON_ZERO)
self.assertContained('native code called abort()', out)

Expand Down Expand Up @@ -13384,7 +13384,7 @@ def test_standard_library_mapping(self):

# Check that the linker was run with `-mt` variants because `-pthread` was passed.
self.assertContained(' -lc-mt-debug ', err)
self.assertContained(' -ldlmalloc-mt ', err)
self.assertContained(' -ldlmalloc-mt-debug ', err)
self.assertContained(' -lcompiler_rt-mt ', err)

def test_explicit_gl_linking(self):
Expand Down
2 changes: 1 addition & 1 deletion tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ def vary_on(cls):
def get_default_variation(cls, **kwargs):
return super().get_default_variation(
malloc=settings.MALLOC,
is_debug=settings.ASSERTIONS >= 2,
is_debug=settings.ASSERTIONS,
is_tracing=settings.EMSCRIPTEN_TRACING,
memvalidate='memvalidate' in settings.MALLOC,
verbose='verbose' in settings.MALLOC,
Expand Down

0 comments on commit 69bcd90

Please sign in to comment.