diff --git a/common/embedded_files.cpp b/common/embedded_files.cpp
index 2ece333880..2ac141c607 100644
--- a/common/embedded_files.cpp
+++ b/common/embedded_files.cpp
@@ -127,10 +127,10 @@ void EMBEDDED_FILES::RemoveFile( const wxString& name, bool aErase )
 
     if( it != m_files.end() )
     {
-        m_files.erase( it );
-
         if( aErase )
             delete it->second;
+
+        m_files.erase( it );
     }
 }