Memory leak in sqlite3.Connection.load_extension()
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
Public issue regarding the issue found by @sushi-gif. Here is a summary of the discussion:
The function sqlite3.Connection.load_extension() has a minor memory leak that occurs when SQLite throws an error while loading an extension (sqlite3_load_extension). According to SQLite specifications, the buffer of the error message must be freed manually after use. The attached PR fixes the issue.
Reproduction code:
import sqlite3
cx = sqlite3.connect(":memory:")
cx.enable_load_extension(True)
for _ in range(1000000):
try:
cx.load_extension("does_not_exist")
except sqlite3.Error:
pass
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-154110
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the implementation of sqlite3.Connection.load_extension() and follow its call to sqlite3_load_extension. Use the supplied repeated failing-load reproduction to examine the error path, and verify that the reported memory leak is fixed without changing successful extension loading behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlite
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100