]> git.saurik.com Git - wxWidgets.git/commitdiff
Make wxDocTemplate::CreateDocument() exceptions-safe.
authorVáclav Slavík <vslavik@fastmail.fm>
Mon, 7 May 2012 12:23:09 +0000 (12:23 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Mon, 7 May 2012 12:23:09 +0000 (12:23 +0000)
Don't create the document object if InitDocument() throws.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71371 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/docview.cpp

index 0154cbdf1e80d09337faf21e4d73318a2b08297b..f44c05e7af58eca43a0cdd42360307e2a516116d 100644 (file)
@@ -859,17 +859,19 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
 bool
 wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags)
 {
+    wxScopeGuard g = wxMakeObjGuard(*doc, &wxDocument::DeleteAllViews);
+
     doc->SetFilename(path);
     doc->SetDocumentTemplate(this);
     GetDocumentManager()->AddDocument(doc);
     doc->SetCommandProcessor(doc->OnCreateCommandProcessor());
 
-    if (doc->OnCreate(path, flags))
-        return true;
+    if ( !doc->OnCreate(path, flags) )
+        return false;
 
-    if (GetDocumentManager()->GetDocuments().Member(doc))
-        doc->DeleteAllViews();
-    return false;
+    g.Dismiss(); // no need to call DeleteAllViews() anymore
+
+    return true;
 }
 
 wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)