← Back to team overview

kicad-developers team mailing list archive

[PATCH] Fix SEGV in module editor when deleting nothing



I get a SEGV in the module editor when using delete on an area without any item:

(gdb) backtrace 
#0  0x000000000067b7f2 in EDA_ITEM::Type (this=0x0) at

#1  0x000000000082f330 in FOOTPRINT_EDIT_FRAME::OnLeftClick
	(this=0x12bde70, DC=0x7fffffffd400, MousePos=...) at

#2  0x00000000009bd78e in EDA_DRAW_PANEL::OnMouseEvent
	(this=0x12ac6d0, event=...) at kicad/common/drawpanel.cpp:967

The following patch fixes it by checking that we have a valid item
before dereferencing it.



Index: b/pcbnew/modedit_onclick.cpp
--- a/pcbnew/modedit_onclick.cpp
+++ b/pcbnew/modedit_onclick.cpp
@@ -122,7 +122,7 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick(
         item = ModeditLocateAndDisplay();
-        if( item->Type() != PCB_MODULE_T ) // Cannot delete the module itself
+        if( item && item->Type() != PCB_MODULE_T ) // Cannot delete the module itself
             SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
             RemoveStruct( item );

Follow ups