Skip to content

Instantly share code, notes, and snippets.

@lvu

lvu/valgrind Secret

Last active June 18, 2016 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvu/99411daf258cb067eece6b30f3bc5923 to your computer and use it in GitHub Desktop.
Save lvu/99411daf258cb067eece6b30f3bc5923 to your computer and use it in GitHub Desktop.
Sample to reproduce the `Cloned python object destroyed inside FindOrCloneDataType()` wxPython issue
==31861== Invalid read of size 8
==31861== at 0x134CBB8B: wxGridTypeRegistry::FindOrCloneDataType(wxString const&) (grid.cpp:9308)
==31861== by 0x134C7935: wxGrid::GetDefaultEditorForType(wxString const&) const (grid.cpp:8002)
==31861== by 0x1312B0B8: meth_wxGrid_GetDefaultEditorForType (sip_gridwxGrid.cpp:3350)
==31861== by 0x4EE5608: PyCFunction_Call (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4F5D5F0: PyEval_EvalFrameEx (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4F5E9E1: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4F5EAC2: PyEval_EvalCodeEx (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4EC8B97: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4E9E0D9: PyObject_Call (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4EB4D63: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4E9E0D9: PyObject_Call (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4EFAA0F: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== Address 0x14fdfcd0 is 0 bytes inside a block of size 128 free'd
==31861== at 0x4C2C104: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==31861== by 0x13150854: sipwxGridCellEditor::~sipwxGridCellEditor() (sip_gridwxGridCellEditor.cpp:81)
==31861== by 0x13152EB1: release_wxGridCellEditor (sip_gridwxGridCellEditor.cpp:1055)
==31861== by 0x13152F2A: dealloc_wxGridCellEditor (sip_gridwxGridCellEditor.cpp:1067)
==31861== by 0x1277D703: forgetObject (siplib.c:11399)
==31861== by 0x1277CFC8: sipWrapper_dealloc (siplib.c:10962)
==31861== by 0x4EF5CF8: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x1276C015: sip_api_parse_result_ex (siplib.c:2532)
==31861== by 0x13120832: sipVH__grid_26(PyGILState_STATE, void (*)(_sipSimpleWrapper*, PyGILState_STATE), _sipSimpleWrapper*, _object*) (sip_gridcmodule.cpp:1100)
==31861== by 0x131511D8: sipwxGridCellEditor::Clone() const (sip_gridwxGridCellEditor.cpp:296)
==31861== by 0x134CBB24: wxGridTypeRegistry::FindOrCloneDataType(wxString const&) (grid.cpp:9302)
==31861== by 0x134C7935: wxGrid::GetDefaultEditorForType(wxString const&) const (grid.cpp:8002)
==31861== Block was alloc'd at
==31861== at 0x4C2B0D8: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==31861== by 0x13152FB0: init_type_wxGridCellEditor (sip_gridwxGridCellEditor.cpp:1082)
==31861== by 0x1277B475: sipSimpleWrapper_init (siplib.c:9861)
==31861== by 0x4EF8DE5: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4E9E0D9: PyObject_Call (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4F574BB: PyEval_EvalFrameEx (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4F5E9E1: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4F5EAC2: PyEval_EvalCodeEx (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4EC8B97: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4E9E0D9: PyObject_Call (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4EB4D63: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4E9E0D9: PyObject_Call (in /usr/lib/libpython3.5m.so.1.0)
==31861==
==31861==
==31861== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==31861== Bad permissions for mapped region at address 0x89748D8
==31861== at 0x89748D8: ??? (in /usr/lib/libstdc++.so.6.0.22)
==31861== by 0x134C7935: wxGrid::GetDefaultEditorForType(wxString const&) const (grid.cpp:8002)
==31861== by 0x1312B0B8: meth_wxGrid_GetDefaultEditorForType (sip_gridwxGrid.cpp:3350)
==31861== by 0x4EE5608: PyCFunction_Call (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4F5D5F0: PyEval_EvalFrameEx (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4F5E9E1: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4F5EAC2: PyEval_EvalCodeEx (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4EC8B97: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4E9E0D9: PyObject_Call (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4EB4D63: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4E9E0D9: PyObject_Call (in /usr/lib/libpython3.5m.so.1.0)
==31861== by 0x4EFAA0F: ??? (in /usr/lib/libpython3.5m.so.1.0)
==31861==
==31861== HEAP SUMMARY:
==31861== in use at exit: 4,689,438 bytes in 18,327 blocks
==31861== total heap usage: 47,508 allocs, 29,181 frees, 12,082,164 bytes allocated
==31861==
==31861== LEAK SUMMARY:
==31861== definitely lost: 1,296 bytes in 3 blocks
==31861== indirectly lost: 6,635 bytes in 271 blocks
==31861== possibly lost: 32,635 bytes in 80 blocks
==31861== still reachable: 4,549,696 bytes in 17,244 blocks
==31861== of which reachable via heuristic:
==31861== length64 : 2,552 bytes in 38 blocks
==31861== newarray : 15,080 bytes in 38 blocks
==31861== suppressed: 0 bytes in 0 blocks
==31861== Rerun with --leak-check=full to see details of leaked memory
==31861==
==31861== For counts of detected and suppressed errors, rerun with: -v
==31861== Use --track-origins=yes to see where uninitialised values come from
==31861== ERROR SUMMARY: 442 errors from 38 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
import wx
import wx.grid
class MyGridCellEditor(wx.grid.GridCellEditor):
clones = []
def Clone(self):
new = MyGridCellEditor()
# uncommenting the line below 'fixes' the issue
# self.clones.append(new)
print('CLONE', self, new)
return new
def __del__(self):
print('DELETE', self, self.GetRefCount())
class MyDataTable(wx.grid.GridTableBase):
def __init__(self):
super().__init__()
def CanGetValueAs(self, row, col, typeName):
return col == 1 and typeName == wx.grid.GRID_VALUE_DATETIME
def GetNumberCols(self):
return 3
def GetNumberRows(self):
return 1
def GetValue(self, row, col):
return ['foo', '2001-01-01', 'bar'][col]
def GetValueAsCustom(self, row, col, typeName):
if col == 1 and typeName == wx.grid.GRID_VALUE_DATETIME:
return wx.DateTime(1, 3, 2013)
class Frame(wx.Frame):
def __init__(self, parent=None, *args, **kwargs):
super().__init__(parent, title='Test')
table = MyDataTable()
table.CanHaveAttributes() # initializes table's AttrProvider
attr = wx.grid.GridCellAttr()
attr.SetRenderer(wx.grid.GridCellDateTimeRenderer())
table.SetColAttr(attr, 1)
self.grid = wx.grid.Grid(self)
self.grid.SetTable(table, True)
def main():
app = wx.App()
frame = Frame()
frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()
import wx
import wx.grid
class MyGridCellEditor(wx.grid.GridCellEditor):
clones = []
def Clone(self):
new = MyGridCellEditor()
# uncommenting the line below 'fixes' the issue
# self.clones.append(new)
print('CLONE', self, new)
return new
def __del__(self):
print('DELETE', self, self.GetRefCount())
class Frame(wx.Frame):
def __init__(self, parent=None, *args, **kwargs):
super().__init__(parent, title='Test')
self.grid = wx.grid.Grid(self)
self.grid.CreateGrid(5, 5)
renderer = wx.grid.GridCellStringRenderer()
editor = MyGridCellEditor()
print('EDITOR', editor)
self.grid.RegisterDataType('foo', renderer, editor)
self.grid.GetDefaultEditorForType('foo:bar')
def main():
app = wx.App()
frame = Frame()
frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment