diff --git a/src/html/htmlwin.cpp b/src/html/htmlwin.cpp
index 19c57ef57c..86e997045a 100644
--- a/src/html/htmlwin.cpp
+++ b/src/html/htmlwin.cpp
@@ -468,8 +468,14 @@ bool wxHtmlWindow::DoSetPage(const wxString& source)
SetBackgroundImage(wxNullBitmap);
m_Parser->SetDC(dc);
-
- delete m_Cell;
+ if (m_Cell)
+ {
+ delete m_Cell;
+ // notice that it's important to set m_Cell to NULL here before calling
+ // Parse() below, even if it will be overwritten by its return value:
+ // without this we may crash if it's used from inside Parse()
+ m_Cell = NULL;
+ }
m_Cell = (wxHtmlContainerCell*) m_Parser->Parse(newsrc);
delete dc;
m_Cell->SetIndent(m_Borders, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);