python / python/cpython

Memory leak in sqlite3.Connection.load_extension()

オープン
#154,109 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

sqlite3.Connection.load_extension() の実装から始め、sqlite3_load_extension の呼び出しを追跡します。提供されている失敗するロードの繰り返し再現を使ってエラーパスを調査し、拡張機能の正常なロード動作を変更せずに、報告されたメモリリークが修正されていることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python, sqlite
領域
databases
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。