[BUG]: PyObject_Type resource leak

オープン 初心者向け
#6,312 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, python
領域
tooling

調査の方向性

include/pybind11/typing.h の 101 行目付近から始め、PYBIND11_OBJECT_DEFAULT(..., PyObject_Type) の宣言を typing::Union、Optional、Final、ClassVar、Literal、TypeVar について調べ、それらの check_ 実装を新しい typing::Object と比較してください。issue はすでにリークを特定しています。PyObject_Type は新しい強い参照を返しますが、check_ はそれを破棄します。まず周囲のマクロ定義を読み、次にそれらの check_ 経路が所有されていない参照を残さなくなったことを、h.ptr() != nullptr のアプローチに合わせて検証してください。完了とは、引数のロードが型参照をリークしなくなったことを意味します。

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

説明

triage
Required prerequisites
What version (or hash if on master) of pybind11 are you using?

a3954715fe849519754abded4d572bf7edab67e3

Problem description

PyObject_Type returns a new strong reference to the object's type object which is never decrefed by the check or check_ functions.
https://docs.python.org/3/c-api/object.html#c.PyObject_Type

@InvincibleRMC it looks like you implemented these. What was the intent with the PyObject_Type check?

AI generated text from #6285
include/pybind11/typing.h:101: each argument load of typing::Union, Optional, Final, ClassVar, Literal or TypeVar leaks one reference to the type of the argument.

  • These classes use PYBIND11_OBJECT_DEFAULT(..., PyObject_Type), and check_ discards the new reference that PyObject_Type returns.
  • Fix: use the same check_ as the new typing::Object (h.ptr() != nullptr).
Reproducible example code

Is this a regression? Put the last known working version here if it is.

Not a regression

主要言語
C++
スター
18k
フォーク
2.3k
平均マージ
5日 7時間
マージ済み PR(30日)
53

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pybind/pybind11 のほかの issue

pybind/pybind11 の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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