Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-395

Need clarification on mongo c-driver

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • None
    • Affects Version/s: None
    • Component/s: None
    • Environment:

      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)

            Assignee:
            Unassigned Unassigned
            Reporter:
            asethy Arati Sethy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: