Calling append_document or append_array was leaking memory asLibBSON.bson_append_document_begin or LibBSON.bson_append_array_begin are not supposed to be called with an already allocated bson handler.
Fix
Replaced bson_append_document_begin + bson_append_document_end combo with a single bson_append_document call. Same fix for arrays.
Issue
Calling
append_document
orappend_array
was leaking memory asLibBSON.bson_append_document_begin
orLibBSON.bson_append_array_begin
are not supposed to be called with an already allocated bson handler.Fix
Replaced
bson_append_document_begin
+bson_append_document_end
combo with a singlebson_append_document
call. Same fix for arrays.