BSON_VALGRIND(3)

πŸ“¦
version 1.23.1 Β· 2 versions
, in debian bookworm

πŸ’… NAME πŸ’…

bson_valgrind β€” the way you use Valgrind to check for BSON data leaks, bestie πŸ•΅οΈβ™€οΈβœ¨


okay so here's the tea. A stack-allocated bson_t comes with a lil internal buffer of its own πŸŽ€ β€” it only heap-allocates extra storage when it actually needs to, and that depends on how big its data is. Which means... if you forget to call bson_destroy() on a stack-allocated bson_t, it might leak. Or it might not. πŸ™ˆ And valgrind might catch it. Or it might not. It's giving chaos, honestly.

So to catch all the potential BSON data leaks in your code, you gotta configure the BSON_MEMCHECK flag like this:

cmake -DCMAKE_C_FLAGS="-DBSON_MEMCHECK -g" .

With this flag set, literally every single bson_t mallocs at least one byte πŸ”₯ (yes, even the tiny ones). So then you run your program's unittests with valgrind and verify that all your bson_t structs got destroyed. No stragglers. No survivors. Periodt. πŸ’€

And one more thing bestie β€” set the environment variable MONGOC_TEST_VALGRIND to on so you skip the timing-dependent tests that are known to fail with valgrind. Those tests are not the vibe under valgrind, trust. 🫢


✨ AUTHOR ✨

MongoDB, Inc πŸ‘‘

2017-present, MongoDB, Inc


and that's the whole page, my love πŸ’– this was libbson version 1.23.1, dated Apr 27, 2026 β€” go forth and destroy your bson_ts, mwah πŸŽ€βœ¨

πŸ“¦ where this page comes from