-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: 1.7.0
-
Component/s: None
Per the mongoc_session_opts_get_transaction_opts docs:
The resulting mongoc_transaction_opt_t should be freed with mongoc_transaction_opts_destroy().
PHPC never frees the return value, which results in a memory leak. The issue dates back to the original implementation of the method in 09f83fa for PHPC-1439. I caught this while reviewing the PR for PHPC-1474, which was adding transaction options to the Session's debug output.
The leak can be verified with:
$ make test TESTS=tests/session/session-getTransactionOptions-001.phpt TEST_PHP_ARGS=-m Build complete. Don't forget to run 'make test'. ===================================================================== PHP : /home/jmikola/bin/php-bin/php-7.4/bin/php PHP_SAPI : cli PHP_VERSION : 7.4.15 ZEND_VERSION: 3.4.0 PHP_OS : Linux - Linux beaker 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 INI actual : /home/jmikola/workspace/mongodb/phpc/tmp-php.ini More .INIs : --------------------------------------------------------------------- PHP : /home/jmikola/bin/php-bin/php-7.4/bin/phpdbg PHP_SAPI : phpdbg PHP_VERSION : 7.4.15 ZEND_VERSION: 3.4.0 PHP_OS : Linux - Linux beaker 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 INI actual : /home/jmikola/workspace/mongodb/phpc/tmp-php.ini More .INIs : --------------------------------------------------------------------- CWD : /home/jmikola/workspace/mongodb/phpc Extra dirs : VALGRIND : valgrind-3.15.0 (memcheck) ===================================================================== Running selected tests. LEAK MongoDB\Driver\Session::getTransactionOptions() [tests/session/session-getTransactionOptions-001.phpt] ===================================================================== Number of tests : 1 1 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 0 ( 0.0%) ( 0.0%) Tests leaked : 1 (100.0%) (100.0%) Tests passed : 0 ( 0.0%) ( 0.0%) --------------------------------------------------------------------- Time taken : 4 seconds ===================================================================== ===================================================================== LEAKED TEST SUMMARY --------------------------------------------------------------------- MongoDB\Driver\Session::getTransactionOptions() [tests/session/session-getTransactionOptions-001.phpt] ===================================================================== make: *** [Makefile:132: test] Error 1
This produces session-getTransactionOptions-001.mem with the following contents:
==281408== 9 bytes in 1 blocks are indirectly lost in loss record 8 of 33 ==281408== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==281408== by 0x792DB6: __zend_malloc (zend_alloc.c:2976) ==281408== by 0x88E0C8F: php_phongo_malloc (php_phongo.c:3346) ==281408== by 0x881B751: bson_malloc (bson-memory.c:70) ==281408== by 0x881DE28: bson_strdup (bson-string.c:329) ==281408== by 0x887F317: mongoc_read_concern_copy (mongoc-read-concern.c:56) ==281408== by 0x8836467: txn_opts_copy (mongoc-client-session.c:75) ==281408== by 0x8837277: mongoc_transaction_opts_clone (mongoc-client-session.c:306) ==281408== by 0x8837B8F: mongoc_session_opts_get_transaction_opts (mongoc-client-session.c:479) ==281408== by 0x890C133: zim_Session_getTransactionOptions (Session.c:308) ==281408== by 0x843747: ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER (zend_vm_execute.h:1730) ==281408== by 0x8A9C61: execute_ex (zend_vm_execute.h:53865) ==281408== ==281408== 720 bytes in 5 blocks are indirectly lost in loss record 28 of 33 ==281408== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==281408== by 0x792DB6: __zend_malloc (zend_alloc.c:2976) ==281408== by 0x792E23: __zend_calloc (zend_alloc.c:2988) ==281408== by 0x88E0CB8: php_phongo_calloc (php_phongo.c:3351) ==281408== by 0x881B7D2: bson_malloc0 (bson-memory.c:108) ==281408== by 0x887F2C6: mongoc_read_concern_new (mongoc-read-concern.c:41) ==281408== by 0x887F304: mongoc_read_concern_copy (mongoc-read-concern.c:55) ==281408== by 0x8836467: txn_opts_copy (mongoc-client-session.c:75) ==281408== by 0x8837277: mongoc_transaction_opts_clone (mongoc-client-session.c:306) ==281408== by 0x8837B8F: mongoc_session_opts_get_transaction_opts (mongoc-client-session.c:479) ==281408== by 0x890C133: zim_Session_getTransactionOptions (Session.c:308) ==281408== by 0x843747: ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER (zend_vm_execute.h:1730) ==281408== ==281408== 840 bytes in 5 blocks are indirectly lost in loss record 29 of 33 ==281408== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==281408== by 0x792DB6: __zend_malloc (zend_alloc.c:2976) ==281408== by 0x792E23: __zend_calloc (zend_alloc.c:2988) ==281408== by 0x88E0CB8: php_phongo_calloc (php_phongo.c:3351) ==281408== by 0x881B7D2: bson_malloc0 (bson-memory.c:108) ==281408== by 0x88B61ED: mongoc_write_concern_new (mongoc-write-concern.c:43) ==281408== by 0x88B6250: mongoc_write_concern_copy (mongoc-write-concern.c:61) ==281408== by 0x883647E: txn_opts_copy (mongoc-client-session.c:76) ==281408== by 0x8837277: mongoc_transaction_opts_clone (mongoc-client-session.c:306) ==281408== by 0x8837B8F: mongoc_session_opts_get_transaction_opts (mongoc-client-session.c:479) ==281408== by 0x890C133: zim_Session_getTransactionOptions (Session.c:308) ==281408== by 0x843747: ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER (zend_vm_execute.h:1730) ==281408== ==281408== 1,360 bytes in 5 blocks are indirectly lost in loss record 31 of 33 ==281408== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==281408== by 0x792DB6: __zend_malloc (zend_alloc.c:2976) ==281408== by 0x792E23: __zend_calloc (zend_alloc.c:2988) ==281408== by 0x88E0CB8: php_phongo_calloc (php_phongo.c:3351) ==281408== by 0x881B7D2: bson_malloc0 (bson-memory.c:108) ==281408== by 0x887F7F8: mongoc_read_prefs_new (mongoc-read-prefs.c:28) ==281408== by 0x887FF59: mongoc_read_prefs_copy (mongoc-read-prefs.c:188) ==281408== by 0x8836496: txn_opts_copy (mongoc-client-session.c:77) ==281408== by 0x8837277: mongoc_transaction_opts_clone (mongoc-client-session.c:306) ==281408== by 0x8837B8F: mongoc_session_opts_get_transaction_opts (mongoc-client-session.c:479) ==281408== by 0x890C133: zim_Session_getTransactionOptions (Session.c:308) ==281408== by 0x843747: ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER (zend_vm_execute.h:1730) ==281408== ==281408== 3,089 (160 direct, 2,929 indirect) bytes in 5 blocks are definitely lost in loss record 33 of 33 ==281408== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==281408== by 0x792DB6: __zend_malloc (zend_alloc.c:2976) ==281408== by 0x792E23: __zend_calloc (zend_alloc.c:2988) ==281408== by 0x88E0CB8: php_phongo_calloc (php_phongo.c:3351) ==281408== by 0x881B7D2: bson_malloc0 (bson-memory.c:108) ==281408== by 0x88371BE: mongoc_transaction_opts_new (mongoc-client-session.c:288) ==281408== by 0x8837260: mongoc_transaction_opts_clone (mongoc-client-session.c:305) ==281408== by 0x8837B8F: mongoc_session_opts_get_transaction_opts (mongoc-client-session.c:479) ==281408== by 0x890C133: zim_Session_getTransactionOptions (Session.c:308) ==281408== by 0x843747: ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER (zend_vm_execute.h:1730) ==281408== by 0x8A9C61: execute_ex (zend_vm_execute.h:53865) ==281408== by 0x8AEBEC: zend_execute (zend_vm_execute.h:57957) ==281408==