getwinerror leaks memory
Created originally on Bitbucket by njs (Nathaniel Smith)
Apparently the following code causes the process’s memory usage to grow without bound:
import cffi
ffi = cffi.FFI()
while True:
a = ffi.getwinerror()
Discovered and isolated here: https://github.com/python-trio/trio/issues/1392
From a quick look at the implementation, I think you might be forgetting to Py_DECREF the message string? The O
BuildValue format increments the reference count; you have to use N
if you want Py_BuildValue
to steal the reference.
Of course trio issues at least one call to getwinerror
on every pass through the scheduler, so this causes a pretty substantial memory leak for long-running programs on Windows…