python / python/cpython

Memory leak in sqlite3.Connection.load_extension()

未关闭
#154,109 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

extension-modules topic-sqlite3 type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 sqlite3.Connection.load_extension() 的实现开始,跟踪其对 sqlite3_load_extension 的调用。使用提供的重复失败加载复现来检查错误路径,并验证报告的内存泄漏已修复,同时不改变扩展成功加载的行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python, sqlite
领域
databases
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。