python / python/cpython

Summary When running _testembed under LeakSanitizer, test_initconfig_get_api reports a memory leak.

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

还没有人认领这个 Issue。

tests topic-C-API type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:
Summary

When running _testembed under LeakSanitizer,
test_initconfig_get_api reports a memory leak.

Reproducer

Build CPython with sanitizers:

./configure \
  --with-pydebug \
  --with-address-sanitizer \
  --with-undefined-behavior-sanitizer
make -j

Run the specific test:

ASAN_OPTIONS=detect_leaks=1 \
./Programs/_testembed test_initconfig_get_api
Observed result

LeakSanitizer reports:

ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1 byte(s) in 1 object(s) allocated from:
    #0  malloc
    #1  PyInitConfig_GetStrList Python/initconfig.c:4024
    #2  test_initconfig_get_api Programs/_testembed.c:1844
Root cause

In test_initconfig_get_api:

  1. The initial call to
PyInitConfig_GetStrList(config, "xoptions", &length, &items)

returns an empty list (length == 0).

  1. The returned items buffer was not freed.
  2. The PyInitConfig *config created by PyInitConfig_Create() was not released before returning.

Under LeakSanitizer, this results in a small direct leak and indirect leaks associated with the configuration lifetime.

Environment
  • Architecture: aarch64-linux-gnu

  • Built with: --with-address-sanitizer

  • Leak detected via: ASAN_OPTIONS=detect_leaks=1

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-145206

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 Programs/_testembed.c 中的 test_initconfig_get_api 开始,检查报告中描述的 PyInitConfig_GetStrList 结果和配置生命周期。运行提供的 sanitizer 构建以及 ./Programs/_testembed test_initconfig_get_api;当测试完成且 LeakSanitizer 未报告直接或相关的配置泄漏时,即表示完成。

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

评估

技术栈
c, python
领域
testing
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 发到你的邮箱

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