0
votes

in my MFC SDI application, i'm trying to override CDocument::DoSave to save my document. I'm using a third part component (TxTextControl) to build a text control. When i save the document, the file is created, but after about one minute my app crashes rising read access error 0xFEEEFEEE, in ole32.dll. This is my code, txtCtrl is my component:

BOOL CEditorTxDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace)
{
CString path, nome;
VARIANT vt1, vt2, vt3;
POSITION pos = GetFirstViewPosition();
CEditorTxView *pView = (CEditorTxView*)this->GetNextView(pos);

VariantInit(&vt1);
vt1.vt = VT_INT;
vt1.intVal = -1;
VariantInit(&vt2);
vt2.vt = VT_INT;
vt2.intVal = 3;
VariantInit(&vt3);
vt3.vt = VT_BOOL;
vt3.boolVal = FALSE;

if (lpszPathName == NULL) {
    CFileDialog fSaveDlg(FALSE);

    fSaveDlg.m_pOFN->lpstrFilter = _T("File Tx (*.tx)");
    fSaveDlg.m_pOFN->lpstrDefExt = _T("tx");
    fSaveDlg.m_pOFN->lpstrTitle = _T("Salva documento");
    fSaveDlg.m_pOFN->lpstrInitialDir = _T("c:");

    if(fSaveDlg.DoModal()==IDOK)
    {
        path = fSaveDlg.GetPathName();
        nome = fSaveDlg.GetFileName();

        pView->txtCtrl.Save(path, vt1, vt2, vt3);
        SetTitle(nome);
        SetModifiedFlag(FALSE);
        SetPathName(path);
    }
} else {
        pView->txtCtrl.Save(GetPathName(), vt1, vt2, vt3);
        SetModifiedFlag(FALSE);
}

return TRUE;
}
1

1 Answers

1
votes

Magic debug values:

FEEEFEEE Used by Microsoft's HeapFree() to mark freed heap memory

That is, the problem comes up from the fact that the code deals with released memory as if it is still alive. To isolate the issue to specific code fragment, debug and use call stack information at the time of exception.