BSON_LIFETIMES(3)
okay so bestie, this is BSON_LIFETIMES(3) from the libbson manual, and itβs literally about keeping your bson_t alive and not leaking memory π
β¨
A bson_t may contain its data directly or may contain pointers to heap-allocated memory. Overwriting an existing bson_t or allowing a stack-allocated bson_t to go out of scope may cause a memory leak. A bson_t should always be destroyed with bson_destroy(). no cap, thatβs the whole vibe check π«Ά
β¨ BSON_T OUT PARAMETERS β¨
A bson_t pointer used as an out parameter must point to valid overwritable storage for a new bson_t which must be one of:
- Uninitialized storage for a
bson_t. - A zero-initialized
bson_tobject. - A
bson_tobject initialized withBSON_INITIALIZER. - A
bson_tobject not created withbson_new()that was destroyed withbson_destroy().
This can be on the stack:
bson_t stack_doc = BSON_INITIALIZER;
example_get_doc (&stack_doc);
bson_destroy (&stack_doc);
Or on the heap:
bson_t *heap_doc = bson_malloc (sizeof (bson_t));
example_get_doc (heap_doc);
bson_destroy (heap_doc);
bson_free (heap_doc);
Omitting bson_destroy() in either case may cause memory leaks. like pls donβt do that π
π¨ WARNING π¨
Passing abson_tpointer obtained frombson_new()as an out parameter will result in a leak of thebson_tstruct. big yikes π
bson_t *heap_doc = bson_new ();
example_get_doc (heap_doc);
bson_destroy (heap_doc); // Leaks the `bson_t` struct!
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
kisses bestie, this was libbson version 2.5.6, dated Oct 09, 2026 πβ¨π
π¦ where this page comes from
- epel 10: libbson-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms