Repository navigation
Fix reference leaks in option parsing - #1085
Merged
Merged
Conversation
_python_ibm_db_parse_options() never released the list returned by PyDict_Keys(), so every set_option(), and every connect()/prepare() given an options dict, leaked one list. Applications that set a statement attribute on each prepared statement grow without bound. The string-value branches of _python_ibm_db_assign_options() also leaked the reference returned by PyUnicode_FromObject(). Add a regression test. Signed-off-by: Robert Cope <robert@copesystems.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release the list returned by
PyDict_Keys()in_python_ibm_db_parse_options()on every return path, and release the reference returned byPyUnicode_FromObject()in the string-value branches of_python_ibm_db_assign_options()(statement, connection and zLOAD attributes). Without this, everyset_option()call, and everyconnect()/prepare()/exec_immediate()given an options dict, leaks memory.Closes #1084
Added
ibm_db_tests/test_6795_SetOptionNoLeak.py. It counts list objects across 2000set_option()calls, both successful and failing, and checks that string option values come back to their starting reference count.Testing (Linux x86_64, Python 3.13, clidriver v11.5.9, Db2 LUW 11.5.8):
python ibmdb_tests.py --sync) fails the same set of tests before and after this change. Those failures are environment gaps in my test database (missing sample tables) and are unrelated to this change.