Debugging a Double Free in Crystal with libxml2, GDB, and Valgrind
dev.to·1d·
Discuss: DEV
🛡️Error Handling
Preview
Report Post

This is a personal note about how I tracked down and fixed a double-free bug caused by Crystal’s garbage collector interacting with libxml2. I used gdb and valgrind to trace the issue, understand where memory was allocated and freed, and eventually identify the root cause. I am not an advanced user of these tools, so this write-up serves as a reminder of the steps I took and what I learned along the way.

The Problem

For a few days, some of my tests started crashing intermittently, against the night builds of the Crystal:

$ bin/drar_test --seed 6690 --verbose --parallel 1

free(): double free detected in tcache 2

  • The crashes were non-deterministic: they didn’t always occur locally, and sometimes didn’t even appear in CI.
  • The error message itself wasn’t ver…

Similar Posts

Loading similar posts...