[CDRIVER-395] Need clarification on mongo c-driver Created: 15/Jul/14  Updated: 03/May/17  Resolved: 16/Jul/14

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement
Reporter: Arati Sethy Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux

Location: http://www.mongodb.org/about/support/
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11
Referrer: http://www.mongodb.org/
Screen Resolution: 1360 x 768
repo: mongodb-www-about
source: support



 Description   

Hi,
I am using libmongoc.so.0.7.0 with tail functionality to read from mongodb.
Valgrind shows leak in this as follows.

------------------------------------------------------------------------------------------------
==00:00:08:55.814 17673== 151,848 (123,120 direct, 28,728 indirect) bytes in 513 blocks are definitely lost in loss record 270 of 272
==00:00:08:55.815 17673== at 0x4C229FE: malloc (vg_replace_malloc.c:291)
==00:00:08:55.815 17673== by 0x4E3104C: bson_malloc (bson.c:952)
==00:00:08:55.815 17673== by 0x4E3735F: mongo_find (mongo.c:1243)
==00:00:08:55.815 17673== by 0x40482A: start_threshold_mongo_log_tailable (mongotosqlite_main.c:481)
==00:00:08:55.815 17673== by 0x619AFC6: start_thread (in /lib64/libpthread-2.8.so)
==00:00:08:55.815 17673== by 0x6A097AC: clone (in /lib64/libc-2.8.so)
==00:00:08:55.815 17673==
==00:00:08:55.815 17673== 745,644 (599,280 direct, 146,364 indirect) bytes in 2,497 blocks are definitely lost in loss record 271 of 272
==00:00:08:55.815 17673== at 0x4C229FE: malloc (vg_replace_malloc.c:291)
==00:00:08:55.815 17673== by 0x4E3104C: bson_malloc (bson.c:952)
==00:00:08:55.815 17673== by 0x4E3735F: mongo_find (mongo.c:1243)
==00:00:08:55.815 17673== by 0x4050A8: start_mongo_log_tailable (mongotosqlite_main.c:724)
==00:00:08:55.815 17673== by 0x619AFC6: start_thread (in /lib64/libpthread-2.8.so)
==00:00:08:55.815 17673== by 0x6A097AC: clone (in /lib64/libc-2.8.so)
==00:00:08:55.815 17673==
----------------------------------------------------------------------------------------------

code snippet.
-------------------
while(1)
{
if(mongo_check_connection (&client_apslog) == MONGO_ERROR )
{
mongo_destroy (&client_apslog);
if (mongo_client (&client_apslog, "127.0.0.1", 27017) != MONGO_OK)

{ syslog(LOG_LOCAL0, " Failed to connect to mongo for Thrshold trhead Err:%s",client_apslog.errstr); }

}
cursor = mongo_find( &client_apslog,table_name , &b, bson_empty( &e ), 0, 0, MONGO_TAILABLE);
if(cursor != NULL)
{
while(mongo_cursor_next( cursor ) == MONGO_OK)

{ bson *curr_doc = mongo_cursor_bson(cursor); ..... }

// end of while(mongo_cursor_next

bson_destroy( &b );
bson_init( &b );
bson_append_start_object( &b, "_id" );
bson_append_oid( &b, "$gt", &id );
bson_append_finish_object( &b );
bson_finish( &b );
}//end of cursor != NULL
}
Can you please advise what is wrong.
I do call bson_destroy(&) at end of while(mongo_cursor_next( cursor ) == MONGO_OK)



 Comments   
Comment by Christian Hergert [ 16/Jul/14 ]

Sorry for the short non-answers above, just cleaning up things before release.

Short answer is, it probably does leak in this situation. The legacy driver didn't really have support for tailable cursors, so it is completely untested. I strongly suggest updating your code to use the new driver. It will be faster, safer, and is to the best of our knowledge, leak free.

Comment by Christian Hergert [ 16/Jul/14 ]

Marking wont fix as the legacy driver is no longer supported.

Comment by Christian Hergert [ 16/Jul/14 ]

Hi, this code is using the legacy driver which is no longer supported. The current version of a C driver has a new API, but also has rigorous valgrind testing.

Generated at Wed Feb 07 21:09:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.