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

mongoc_collection_aggregate() leaks a mongoc_read_concern_t/mongoc_write_concern_t, if read/write concern unspecified by the user

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.0
    • Affects Version/s: 1.5.0
    • Component/s: None
    • None

      Calling mongoc_collection_aggregate() will cause a leak of a mongoc_read_concern_t object, if the user does not specify a "readConcern" field in the command options. In addition, calling mongoc_collection_aggregate() will cause a leak of a mongoc_write_concern_t object, if the user does not specify a "writeConcern" field in the command options and the given pipeline includes a $out stage.

      Regression introduced in 1.5.0-rc3 by https://github.com/mongodb/mongo-c-driver/commit/adfff3aa7fadd61063f82d6c0e5d35d655552d74 (CDRIVER-1704).

      Reproduce with the following shell script:

      git checkout 1.5.0-rc3
      ./configure --enable-debug --with-libbson=bundled
      make -j32
      ./aggregation1
      valgrind --leak-check=full .libs/lt-aggregation1
      

      After running the above, valgrind outputs the following:

      ==1291== HEAP SUMMARY:
      ==1291==     in use at exit: 92,280 bytes in 3,085 blocks
      ==1291==   total heap usage: 3,532 allocs, 447 frees, 268,114 bytes allocated
      ==1291==
      ==1291== 256 bytes in 1 blocks are definitely lost in loss record 536 of 582
      ==1291==    at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
      ==1291==    by 0x50CC79E: bson_malloc0 (bson-memory.c:105)
      ==1291==    by 0x4E6F263: mongoc_read_concern_new (mongoc-read-concern.c:40)
      ==1291==    by 0x4E5BEBB: _mongoc_cursor_new_with_opts (mongoc-cursor.c:301)
      ==1291==    by 0x4E5C5F4: _mongoc_cursor_new (mongoc-cursor.c:470)
      ==1291==    by 0x4E55031: _mongoc_collection_cursor_new (mongoc-collection.c:65)
      ==1291==    by 0x4E55675: mongoc_collection_aggregate (mongoc-collection.c:329)
      ==1291==    by 0x400EBB: print_pipeline (aggregation1.c:18)
      ==1291==    by 0x400FF0: main (aggregation1.c:47)
      ==1291==
      ==1291== LEAK SUMMARY:
      ==1291==    definitely lost: 256 bytes in 1 blocks
      ==1291==    indirectly lost: 0 bytes in 0 blocks
      ==1291==      possibly lost: 0 bytes in 0 blocks
      ==1291==    still reachable: 92,024 bytes in 3,084 blocks
      ==1291==         suppressed: 0 bytes in 0 blocks
      

            Assignee:
            bjori Hannes Magnusson
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: