Alex, you should replace malloc for bson_malloc()