Skip to content

fix: avoid retaining Database.info results - #273

Draft
sricharanreddycheruku wants to merge 1 commit into
darvid:mainfrom
sricharanreddycheruku:batch3-database-info-reference
Draft

sricharanreddycheruku wants to merge 1 commit into
darvid:mainfrom
sricharanreddycheruku:batch3-database-info-reference

Conversation

@sricharanreddycheruku

Copy link
Copy Markdown

Database.info() leaks its returned bytes object on every successful call.
PyBytes_FromString() already returns a new reference, but the extra
Py_INCREF() leaves one reference behind after the caller discards the result.
Repeated database inspection therefore accumulates memory indefinitely.

Return the existing new reference after freeing the native info string. This
also allows a failed bytes allocation to propagate its NULL result rather than
incrementing a NULL pointer; allocation failure was not injected locally.

Add four bounded allocation regressions beside the existing info test, covering
block, stream, vectored and Chimera databases. Each discards 1,000 info results
and checks allocations traced to the test file. The test preserves an existing
tracemalloc session and allows 4 KiB for bookkeeping. On the original extension,
those calls retain 71–79 KiB on Python 3.12 and 87–95 KiB on free-threaded 3.14.
A separate snapshot reproducer confirms 1,000 retained bytes objects per mode
before the fix and none afterward.

Validation on Linux with source-built wheels and PYTHONMALLOC=debug:

  • All four new cases fail before and pass after on Python 3.12.14 and
    free-threaded 3.14.7.
  • Free-threaded 3.14 full suite: 34 passed, 4 existing skips; importing the
    extension keeps the GIL disabled.
  • Python 3.12 full suite: 35 passed, 2 skips, 1 existing Unicode expression
    lifetime failure addressed separately by Release compile metadata references and propagate ID lookup errors #265. This branch does not include
    that fix.
  • C formatting, source Black/Ruff, formatting/lint of the new test addition,
    and git diff --check pass. Existing unrelated formatting/lint issues in
    tests/test_hyperscan.py are unchanged.

Independent branch from current main; no linked issue or API change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant