This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jeremy.kloth
Recipients jeremy.kloth, jkloth, vstinner
Date 2022-02-26.03:18:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAGvrs3KzZU5Nr7jvxrt=uNU4UJN9zU8+iOKHhhbCTF5sKG7wRQ@mail.gmail.com>
In-reply-to <1645840252.45.0.915416762124.issue46857@roundup.psfhosted.org>
Content
> Oh wow. How did you find this leak? Did you read all C files and check for code specific to Windows? How did you proceed? Well spotted!

Initially, I modified Py_INCREF to dump the object (addr & tp_name) on
initial inc (ob_refcnt == 1) and Py_DECREF to dump on final dec
(ob_refcnt == 0).
Then filter that list (~65K) to find objects not dealloc'ed.  Given
those names (~200), cross-check with source files containing 'ifdef
MS_WINDOWS' (and related spellings).

> Which command do you type? Do you pass -I option to Python?

For both as -I disables environment lookup:
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -757,6 +757,7 @@ config_init_defaults(PyConfig *config)
    config->user_site_directory = 1;
    config->buffered_stdio = 1;
    config->pathconfig_warnings = 1;
+   config->dump_refs = 1;
#ifdef MS_WINDOWS
    config->legacy_windows_stdio = 0;
#endif

For linux:
./configure --enabled-shared --with-py-debug --with-trace-refs
make build_all
LD_LIBRARY_PATH=$PWD ./python -X showrefcount -I -c pass

For Windows:
Add "#define Py_TRACE_REFS 1" to PC\pyconfig.h
build.bat -d -e
amd64\python_d.exe -X showrefcount -I -c pass

> I proposed GH-31594 to fix this macro.

Even using that change, I still have negative refs (but I still have
Py_TRACE_REFS defined)
History
Date User Action Args
2022-02-26 03:18:28jeremy.klothsetrecipients: + jeremy.kloth, vstinner, jkloth
2022-02-26 03:18:28jeremy.klothlinkissue46857 messages
2022-02-26 03:18:27jeremy.klothcreate