Fix memory leak in wxRibbonToolBar in case of error.
Use wxScopedPtr to ensure the tool is not leaked, even if we fail to insert it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75959 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "wx/ribbon/art.h"
|
#include "wx/ribbon/art.h"
|
||||||
#include "wx/ribbon/bar.h"
|
#include "wx/ribbon/bar.h"
|
||||||
#include "wx/dcbuffer.h"
|
#include "wx/dcbuffer.h"
|
||||||
|
#include "wx/scopedptr.h"
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#endif
|
#endif
|
||||||
@@ -244,7 +245,7 @@ wxRibbonToolBarToolBase* wxRibbonToolBar::InsertTool(
|
|||||||
wxASSERT(bitmap.IsOk());
|
wxASSERT(bitmap.IsOk());
|
||||||
|
|
||||||
// Create the wxRibbonToolBarToolBase with parameters
|
// Create the wxRibbonToolBarToolBase with parameters
|
||||||
wxRibbonToolBarToolBase* tool = new wxRibbonToolBarToolBase;
|
wxScopedPtr<wxRibbonToolBarToolBase> tool(new wxRibbonToolBarToolBase);
|
||||||
tool->id = tool_id;
|
tool->id = tool_id;
|
||||||
tool->bitmap = bitmap;
|
tool->bitmap = bitmap;
|
||||||
if(bitmap_disabled.IsOk())
|
if(bitmap_disabled.IsOk())
|
||||||
@@ -270,8 +271,10 @@ wxRibbonToolBarToolBase* wxRibbonToolBar::InsertTool(
|
|||||||
size_t tool_count = group->tools.GetCount();
|
size_t tool_count = group->tools.GetCount();
|
||||||
if(pos <= tool_count)
|
if(pos <= tool_count)
|
||||||
{
|
{
|
||||||
group->tools.Insert(tool, pos);
|
// Give the ownership of the tool to group->tools
|
||||||
return tool;
|
wxRibbonToolBarToolBase* const p = tool.release();
|
||||||
|
group->tools.Insert(p, pos);
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
pos -= tool_count + 1;
|
pos -= tool_count + 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user