crash on the end of release mode
-
morning, this app runs fine on debug mode, but got access violation at the exiting dialog in release, I checked the thread, it was trying to close [CCallsmDbf::~CCallsmDbf]....here is part of the code that causing problem, but I am not sure what need to be fixed, thanks! CCallsmDbf::CCallsmDbf(char *dbfname, int exclusive) : CB_DBF_NTX(dbfname, exclusive) { if (validDBF()) { ptrIdxName = m_csIdxFile.GetBuffer( L_tmpnam + 1 ); GetTempFileName( ".", "callsm", 0, ptrIdxName ); index_on( ptrIdxName, "ANI" ); m_csIdxFile.ReleaseBuffer(); top(); BindFieldOrdinals(); } } CCallsmDbf::~CCallsmDbf() { } in header file, protected: CString m_csIdxFile; char* ptrIdxName;
-
morning, this app runs fine on debug mode, but got access violation at the exiting dialog in release, I checked the thread, it was trying to close [CCallsmDbf::~CCallsmDbf]....here is part of the code that causing problem, but I am not sure what need to be fixed, thanks! CCallsmDbf::CCallsmDbf(char *dbfname, int exclusive) : CB_DBF_NTX(dbfname, exclusive) { if (validDBF()) { ptrIdxName = m_csIdxFile.GetBuffer( L_tmpnam + 1 ); GetTempFileName( ".", "callsm", 0, ptrIdxName ); index_on( ptrIdxName, "ANI" ); m_csIdxFile.ReleaseBuffer(); top(); BindFieldOrdinals(); } } CCallsmDbf::~CCallsmDbf() { } in header file, protected: CString m_csIdxFile; char* ptrIdxName;
Hi, ptrIdxName = m_csIdxFile.GetBuffer( L_tmpnam + 1 ); This line looks dangerous! L_tmpnam may not be initialized. which would assign an unpredictable amount of mem. in release mode. The memory pointed to by ptrIdxName might easily be corrupted by the "GetTempFileName" call on the next line... the problem might only manifest itself when the class destructor deallocates the memory at object destruction time. Why not try a simpler way of doing this instead of GetBuffer/ReleaseBuffer like... TCHAR filename[MAX_PATH]; GetTempFileName( ,,, filename ); m_csIdxFile = filename; Cheers, Dave
-
Hi, ptrIdxName = m_csIdxFile.GetBuffer( L_tmpnam + 1 ); This line looks dangerous! L_tmpnam may not be initialized. which would assign an unpredictable amount of mem. in release mode. The memory pointed to by ptrIdxName might easily be corrupted by the "GetTempFileName" call on the next line... the problem might only manifest itself when the class destructor deallocates the memory at object destruction time. Why not try a simpler way of doing this instead of GetBuffer/ReleaseBuffer like... TCHAR filename[MAX_PATH]; GetTempFileName( ,,, filename ); m_csIdxFile = filename; Cheers, Dave
But it's still crashes at the same spot. when the access violation message show up, there were two threads [CCallsmDbf::~CCallsmDbf] and [CDialog::EndDialog], I gess the problem could be at the CDialog as well.... and it's not crash every single time of on release mode, every now and then it works...... thanks for your time!
-
But it's still crashes at the same spot. when the access violation message show up, there were two threads [CCallsmDbf::~CCallsmDbf] and [CDialog::EndDialog], I gess the problem could be at the CDialog as well.... and it's not crash every single time of on release mode, every now and then it works...... thanks for your time!
Problem could be still suggested by Dave. I think one or more extra bits are accessed somewhere. Try to keep track of character pointer used. use strcpy() wherever needed, and with care
-
Problem could be still suggested by Dave. I think one or more extra bits are accessed somewhere. Try to keep track of character pointer used. use strcpy() wherever needed, and with care
thanks for your info, here is another function that from same file, somehow, it's done deifferently..... CFavNatDbf::CFavNatDbf(int exclusive) : CB_DBF_NTX("DATA\\FAVNAT.DBF", exclusive) { if (validDBF()) { char* ptrIdxName = m_csIdxFile.GetBuffer( L_tmpnam + 1 ); GetTempFileName( ".", "favnat", 0, ptrIdxName ); _strupr( ptrIdxName ); memmove( ptrIdxName, ptrIdxName + 2, strlen( ptrIdxName ) - 2 ); *strstr( ptrIdxName, ".TMP" ) = '\0'; index_on( ptrIdxName, "CUST_NUM + LOCATION" ); m_csIdxFile.ReleaseBuffer(); top(); BindFieldOrdinals(); } } CFavNatDbf::~CFavNatDbf() { } void CFavNatDbf::BindFieldOrdinals() { }