Fix memory leak in Python pcbnew.FootprintLoad()

PCB_IO_MGR::FindPlugin() returns a new PCB_IO* that the caller owns. The
Python wrapper functions (FootprintLoad, FootprintSave, etc.) in
footprint.i call GetPluginForPath which calls FindPlugin, but the
returned plugin object was never deleted because SWIG didn't know
Python owned it.

The %newobject directive tells SWIG that Python owns the returned
PCB_IO* and should delete it when the Python object is garbage
collected.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/22526
This commit is contained in:
Seth Hillbrand
2026-01-06 04:45:06 -08:00
parent 127a85f753
commit 0f0fbc55d7
+5
View File
@@ -94,6 +94,11 @@ wxArrayString GetFootprints(const wxString& aNickName);
%}
// Tell SWIG that the caller owns the PCB_IO* returned by FindPlugin and is
// responsible for deleting it. This fixes memory leaks in Python wrapper
// functions like FootprintLoad that call GetPluginForPath -> FindPlugin.
%newobject PCB_IO_MGR::FindPlugin;
%include <pcb_io/pcb_io_mgr.h>
%include <pcb_io/pcb_io.h>