[CDRIVER-1046] _mongoc_cursor_run_command() may leak cursor->reader Created: 09/Dec/15  Updated: 18/Jan/16  Resolved: 09/Dec/15

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.3.0
Fix Version/s: 1.3.1

Type: Bug Priority: Major - P3
Reporter: Jeremy Mikola Assignee: Jeremy Mikola
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by PHPC-450 MongoDB 3.2 Compatibility Closed

 Description   

Comparing _mongoc_cursor_run_command()'s call to bson_reader_new_from_data() with other instances through libmongoc, I noticed that it doesn't check and free a previously allocated reader. I believe this is related to the following memory leaked spotted in several PHPC test failures:

==10816== 160 bytes in 1 blocks are definitely lost in loss record 38 of 94
==10816==    at 0x4C2BBA0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10816==    by 0x911A2F: _emalloc (zend_alloc.c:2427)
==10816==    by 0x911D91: _safe_emalloc (zend_alloc.c:2583)
==10816==    by 0x911EE4: _ecalloc (zend_alloc.c:2610)
==10816==    by 0x96F98F4: php_phongo_calloc (php_phongo.c:2030)
==10816==    by 0x96A4E4D: bson_malloc0 (bson-memory.c:103)
==10816==    by 0x96A654C: bson_reader_new_from_data (bson-reader.c:541)
==10816==    by 0x96C0898: _mongoc_cursor_run_command (mongoc-cursor.c:559)
==10816==    by 0x96C3A1D: _mongoc_cursor_cursorid_refresh_from_command (mongoc-cursor-cursorid.c:72)
==10816==    by 0x96C3E1A: _mongoc_cursor_cursorid_prime (mongoc-cursor-cursorid.c:136)
==10816==    by 0x96C4259: _mongoc_cursor_cursorid_next (mongoc-cursor-cursorid.c:224)
==10816==    by 0x96C1323: _mongoc_cursor_find_command (mongoc-cursor.c:775)



 Comments   
Comment by Githook User [ 10/Dec/15 ]

Author:

{u'username': u'jmikola', u'name': u'Jeremy Mikola', u'email': u'jmikola@gmail.com'}

Message: Bump libmongoc for CDRIVER-1046 memory leak fix
Branch: master
https://github.com/mongodb/mongo-php-driver/commit/261da85e815b3b6d6fec9422b103696541195605

Comment by Githook User [ 09/Dec/15 ]

Author:

{u'username': u'jmikola', u'name': u'Jeremy Mikola', u'email': u'jmikola@gmail.com'}

Message: CDRIVER-1046: Free BSON reader before new assignment
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/4039c286539fc9150f90c10baef3ca3598c50e56

Comment by Jeremy Mikola [ 09/Dec/15 ]

https://github.com/mongodb/mongo-c-driver/pull/303

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