From 0f0fbc55d7a331d56ff3939c02e6b5d2dcb69783 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 6 Jan 2026 04:45:06 -0800 Subject: [PATCH] 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 --- pcbnew/python/swig/pcbnew.i | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pcbnew/python/swig/pcbnew.i b/pcbnew/python/swig/pcbnew.i index dbedfb9a6b..a3f56483ac 100644 --- a/pcbnew/python/swig/pcbnew.i +++ b/pcbnew/python/swig/pcbnew.i @@ -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 %include