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:
Vadim Zeitlin
2014-02-21 00:51:58 +00:00
parent 5e204ab52e
commit 5ac26f43bd

View File

@@ -20,6 +20,7 @@
#include "wx/ribbon/art.h"
#include "wx/ribbon/bar.h"
#include "wx/dcbuffer.h"
#include "wx/scopedptr.h"
#ifndef WX_PRECOMP
#endif
@@ -244,7 +245,7 @@ wxRibbonToolBarToolBase* wxRibbonToolBar::InsertTool(
wxASSERT(bitmap.IsOk());
// Create the wxRibbonToolBarToolBase with parameters
wxRibbonToolBarToolBase* tool = new wxRibbonToolBarToolBase;
wxScopedPtr<wxRibbonToolBarToolBase> tool(new wxRibbonToolBarToolBase);
tool->id = tool_id;
tool->bitmap = bitmap;
if(bitmap_disabled.IsOk())
@@ -270,8 +271,10 @@ wxRibbonToolBarToolBase* wxRibbonToolBar::InsertTool(
size_t tool_count = group->tools.GetCount();
if(pos <= tool_count)
{
group->tools.Insert(tool, pos);
return tool;
// Give the ownership of the tool to group->tools
wxRibbonToolBarToolBase* const p = tool.release();
group->tools.Insert(p, pos);
return p;
}
pos -= tool_count + 1;
}