python / python/cpython

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

Aperta
#145,204 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

tests topic-C-API type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in Programs/_testembed.c, in test_initconfig_get_api, e rivedi il risultato di PyInitConfig_GetStrList e la durata della configurazione descritta nel report. Esegui la build con sanitizer fornita e ./Programs/_testembed test_initconfig_get_api; il lavoro è completato quando il test termina senza che LeakSanitizer segnali leak diretti o associati della configurazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, python
Ambito
testing
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.