in function: mongoc_collection_find_and_modify
if reply is created by bson_new(), will cause memory leakage.
code:
use example in
http://api.mongodb.org/c/current/mongoc_collection_find_and_modify.html
just replace
bson_t reply;
with
bson_t* reply = bson_new();
then will cause memory leakage:
bson_t* reply = bson_new() ... if (!mongoc_collection_find_and_modify (collection, query, NULL, update, NULL, false, false, true, reply, &error)) ... bson_destroy (reply); ...
reason:
mongoc_collection_find_and_modify use bson_copy_to() or bson_init() to set reply. These two function used with bson_t object created by bson_new() will cause memory leakage.
eg:
1.
bson_t * doc = bson_new(); bson_init(doc); bson_destroy(doc);
2.
bson_t * src= bson_new(); bson_t * dst= bson_new(); bson_copy_to(src, dst); bson_destroy(src); bson_destroy(dst);
both code piece of code will cause memory leakage.