From: "sephiroth AT id-base DOT com" Newsgroups: comp.os.msdos.djgpp Subject: delete C++ command. Date: Sun, 24 Oct 1999 16:01:50 +0100 Organization: NTL Internet News Service Lines: 710 Message-ID: <38131F5D.9B84ECAD@id-base.com> NNTP-Posting-Host: p28-mizar-rea.tch.cableol.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: nclient7-gui.server.ntli.net 940777383 25768 194.168.35.28 (24 Oct 1999 15:03:03 GMT) X-Complaints-To: abuse AT net DOT ntl DOT com NNTP-Posting-Date: 24 Oct 1999 15:03:03 GMT X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Why does the delete function crash programs on rare occasions? I think this happens when the delete is called at the end of the program. What causes this????? How can I prevent it happening??. Thanx in advance for ANY help. If you want to look at my source if it helps: here it is: /* ============================================================================ dj shinyblue( sephiroth AT id-base DOT com ) presents: A programming File. (C)copyright 1999 dj shinyblue. FileName: bclboard.cpp Author: dj shinyblue Notes: Message Board. ============================================================================ */ #include "bclboard.h" char cWorkingVersion[] = "(BCLBOARD.CPP REVISION 24/OCTOBER/1999)"; char * BCLBOARD_ToUpper( char *cpToUpper ); short BCLBOARD_ReadMessage(); short BCLBOARD_SubmitMessage(); long BCLBOARD_GetFileLength( FILE *fpFileSize ); short BCLBOARD_MakeNewNodeFile( clConfig *clcNewFile ); short BCLBOARD_ReadNodeFile( clConfig *clcOpenFile ); short BCLBOARD_ReWriteNodeHeader( clConfig *clcReWriteFile ); stNodeHeader stndMainHeader; clCGISession clcsMessageBoard; //This is causing the problems!!! short sBlockNumber; int main( int argc , char *argv[] ) { stFormEntry stfeType; if( !clcsMessageBoard.CGI_ReturnSessionSuccess() ) { clcsMessageBoard.CGI_ReDirect( "http://127.0.0.1" ); clcsMessageBoard.CGI_EndHTTPHeader(); return 0; } sBlockNumber = clcsMessageBoard.CGI_SearchFormValues( "type" , 1 ); if( sBlockNumber == -1 ) { clcsMessageBoard.CGI_ReDirect( "http://127.0.0.1" ); clcsMessageBoard.CGI_EndHTTPHeader(); return 0; } else { stfeType = clcsMessageBoard.CGI_ReturnFormValue( sBlockNumber ); if( strcmp( "READMSG" , BCLBOARD_ToUpper( stfeType.sm_cpFieldValue ) ) == 0 ) { clcsMessageBoard.CGI_ReDirect( "http://127.0.0.1" ); clcsMessageBoard.CGI_EndHTTPHeader(); return 0; } else if( strcmp( "REPLYMSG" , BCLBOARD_ToUpper( stfeType.sm_cpFieldValue ) ) == 0 ) { clcsMessageBoard.CGI_ReDirect( "http://127.0.0.1" ); clcsMessageBoard.CGI_EndHTTPHeader(); return 0; } else if( strcmp( "SUBMITMSG" , BCLBOARD_ToUpper( stfeType.sm_cpFieldValue ) ) == 0 ) { if( !BCLBOARD_SubmitMessage() ) { clcsMessageBoard.CGI_ReDirect( "http://127.0.0.1" ); clcsMessageBoard.CGI_EndHTTPHeader(); return 0; } else { clcsMessageBoard.CGI_SetContentType( "text/html" ); clcsMessageBoard.CGI_EndHTTPHeader(); printf( "Message Done!!" ); return 0; } } else { clcsMessageBoard.CGI_ReDirect( "http://127.0.0.1" ); clcsMessageBoard.CGI_EndHTTPHeader(); return 0; } } } short BCLBOARD_ReadMessage() { return 1; } long BCLBOARD_GetFileLength( FILE *fpFileSize ) { long lReturnPosition; long lReturnPosition2; lReturnPosition = ftell( fpFileSize ); fseek( fpFileSize , 0 , SEEK_END ); lReturnPosition2 = ftell( fpFileSize ); fseek( fpFileSize , lReturnPosition , SEEK_SET ); return lReturnPosition2; } short BCLBOARD_MakeNewNodeFile( clConfig *clcNewFile ) { clcNewFile->CONFIG_WriteNormChar( CONST_S_METABOARDID , strlen( CONST_S_METABOARDID ) ); clcNewFile->CONFIG_WriteLongChunk( 0 ); clcNewFile->CONFIG_WriteShortChunk( CONST_N_THREAD_DIM ); } short BCLBOARD_ReadNodeFile( clConfig *clcOpenFile ) { stndMainHeader.cpHeaderID = clcOpenFile->CONFIG_ReadNormChar( strlen ( CONST_S_METABOARDID ) ); stndMainHeader.lMessageTrees = clcOpenFile->CONFIG_ReadLongChunk(); stndMainHeader.sReplysPerTree = clcOpenFile->CONFIG_ReadShortChunk(); } short BCLBOARD_ReWriteNodeHeader( clConfig *clcReWriteFile ) { clcReWriteFile->CONFIG_WriteNormChar( stndMainHeader.cpHeaderID , strlen( stndMainHeader.cpHeaderID ) ); clcReWriteFile->CONFIG_WriteLongChunk( stndMainHeader.lMessageTrees ); clcReWriteFile->CONFIG_WriteShortChunk( stndMainHeader.sReplysPerTree ); } short BCLBOARD_SubmitMessage() { short sNameEntry = -1; short sEmailEntry = -1; short sSubjectEntry = -1; short sMessageEntry = -1; short sThreadEntry = -1; clConfig *clcNodeFile; if( ( sNameEntry = clcsMessageBoard.CGI_SearchFormValues( "name" , 1 ) ) != -1 ) if( ( sEmailEntry = clcsMessageBoard.CGI_SearchFormValues( "e-mail" , 1 ) ) != -1 ) if( ( sSubjectEntry = clcsMessageBoard.CGI_SearchFormValues( "subject" , 1 ) ) != -1 ) if( ( sMessageEntry = clcsMessageBoard.CGI_SearchFormValues( "message" , 1 ) ) != -1 ){} else return 0; else return 0; else return 0; else return 0; clcNodeFile = new clConfig( CONST_S_NODENAME , 1 ); if( !clcNodeFile->CONFIG_ReturnFileStatus() ) { delete clcNodeFile; clcNodeFile = new clConfig( CONST_S_NODENAME , 0 ); if( !clcNodeFile->CONFIG_ReturnFileStatus() ) { delete clcNodeFile; return 0; } BCLBOARD_MakeNewNodeFile( clcNodeFile ); clcNodeFile->CONFIG_Rewind(); } delete clcNodeFile; fprintf( stderr , "\n\nk, here\n\n" ); clcNodeFile = new clConfig( CONST_S_NODENAME , 1 ); BCLBOARD_ReadNodeFile( clcNodeFile ); fprintf( stderr , "\n\nMade it here!\n\n" ); delete clcNodeFile; fprintf( stderr , "\n\nMade it here ALSO!\n\n" ); return 1; } char * BCLBOARD_ToUpper( char *cpToUpper ) { int iDifference; char *cpReturnString; char *cpReturnPointer; if( 'A' > 'a' ) iDifference = 'A' - 'a'; else iDifference = 'a' - 'A'; cpReturnString = new char [ strlen( cpToUpper ) + 1 ]; if( !cpReturnString ) return 0; memset( cpReturnString , 0 , strlen( cpToUpper ) + 1 ); strcpy( cpReturnString , cpToUpper ); cpReturnPointer = cpReturnString; while( *cpToUpper ) { if( *cpToUpper >= 'a' && *cpToUpper <= 'z' ) { if( 'A' > 'a' ) *( cpReturnString ) += iDifference; else *( cpReturnString ) -= iDifference; } cpToUpper++; cpReturnString++; } cpReturnString = cpReturnPointer; return cpReturnString; } Ok, that's the main file, and if your interested, heres the file causing the problem: /* ============================================================================ dj shinyblue( sephiroth AT id-base DOT com ) presents: A programming File. (C)copyright 1999 dj shinyblue. FileName: clCGISession.cpp Author: dj shinyblue Notes: Heavy duty CGI Class. ============================================================================ */ #include #include #include #include "dtype.h" /* Public Functions Below: */ clCGISession::clCGISession() { g_sRequestMethod; g_sCombinationNumber = 0; g_sNumberOfHexPairs = 0; CGI_GetMethodType(); cpRawUrl = CGI_GetRawUrl(); if( !CGI_GetFormValues( cpRawUrl ) ) sSessionSuccess = 0; else { sSessionSuccess = 1; sCleanFlag = 0; } } clCGISession::clCGISession( char *cpRawUrl2 ) { if( !CGI_GetFormValues( cpRawUrl2 ) ) sSessionSuccess = 0; else sSessionSuccess = 1; } clCGISession::~clCGISession() { // if( !sCleanFlag ) // CGI_CleanUpSession(); //This is what causes the problem. } void clCGISession::CGI_CleanUpSession() { delete [] cpRawUrl; for( long lLoopX = 0 ; lLoopX < g_sCombinationNumber ; lLoopX++ ) { delete [] stfeMainBlock[ lLoopX ].sm_cpFieldName; delete [] stfeMainBlock[ lLoopX ].sm_cpFieldValue; stfeMainBlock[ lLoopX ].sm_cpFieldName = 0; stfeMainBlock[ lLoopX ].sm_cpFieldValue = 0; } sCleanFlag = 1; } short clCGISession::CGI_ReturnSessionSuccess() { return sSessionSuccess; } short clCGISession::CGI_ReturnHeaderCheck() { return sHeaderCheckFlag; } stFormEntry clCGISession::CGI_ReturnFormValue( short sFormValue ) { if( sFormValue <= g_sCombinationNumber ) return stfeMainBlock[ sFormValue ]; } long clCGISession::CGI_SearchFormValues( char *cpSearch , short sSearchType ) { long lLoopX = 0; for( lLoopX = 0 ; lLoopX < g_sCombinationNumber ; lLoopX++ ) { if( sSearchType == 0 ) { if( strcmp( cpSearch , stfeMainBlock[ lLoopX ].sm_cpFieldName ) == 0 ) { return lLoopX; } } if( sSearchType == 1 ) { if( strcmp( CGI_ToUpper( cpSearch ) , CGI_ToUpper( stfeMainBlock[ lLoopX ].sm_cpFieldName ) ) == 0 ) { if( cpTrashPointer ) delete [] cpTrashPointer; return lLoopX; } } } return -1; } void clCGISession::CGI_SetContentType( char *cpConType ) { printf( "Content-type: %s\n" , cpConType ); } void clCGISession::CGI_ReDirect( char *cpLocation ) { printf( "Location: %s\n" , cpLocation ); } void clCGISession::CGI_EndHTTPHeader() { printf( "\n" ); sHeaderCheckFlag = 0; } /* Private Functions Below; */ char * clCGISession::CGI_ToUpper( char *cpToUpper ) { int iDifference; char *cpReturnString; char *cpReturnPointer; if( 'A' > 'a' ) iDifference = 'A' - 'a'; else iDifference = 'a' - 'A'; cpReturnString = new char [ strlen( cpToUpper ) + 1 ]; if( !cpReturnString ) return 0; memset( cpReturnString , 0 , strlen( cpToUpper ) + 1 ); strcpy( cpReturnString , cpToUpper ); cpReturnPointer = cpReturnString; while( *cpToUpper ) { if( *cpToUpper >= 'a' && *cpToUpper <= 'z' ) { if( 'A' > 'a' ) *( cpReturnString ) += iDifference; else *( cpReturnString ) -= iDifference; } cpToUpper++; cpReturnString++; } cpReturnString = cpReturnPointer; cpTrashPointer = cpReturnString; return cpReturnString; } long clCGISession::CGI_GetLengthBefore( char *cpRawUrl ) { long lReadLength = 0; long lStringLength = 0; lStringLength = strlen( cpRawUrl ); while( lReadLength <= lStringLength ) { if( *cpRawUrl == '&' || *cpRawUrl == CONST_CSPLITIDENTIFIER ) { return lReadLength; } if( *cpRawUrl == CONST_CHEXIDENTIFIER ) { g_sNumberOfHexPairs++; cpRawUrl += 2; lReadLength++; } else lReadLength++; cpRawUrl++; } return lReadLength; } long clCGISession::CGI_GetNumberOfSets( char *cpRawUrl ) { short sSpidFlag = 0; long lCount = 0; char *cpRawUrl2; cpRawUrl2 = cpRawUrl; while( *cpRawUrl2 ) { if( *cpRawUrl2 == CONST_CSPLITIDENTIFIER ) { sSpidFlag = 1; } if( *cpRawUrl2 == '&' && sSpidFlag == 0 ) return 0; if( *cpRawUrl2 == '&' && sSpidFlag == 1 ) { lCount++; sSpidFlag = 0; } cpRawUrl2++; if( *cpRawUrl2 == 0 && sSpidFlag == 0 ) return 0; if( *cpRawUrl2 == 0 && sSpidFlag == 1 ) { lCount++; sSpidFlag = 0; } } return lCount; } char clCGISession::CGI_ReturnHexValue( char *cpRawUrl ) { char *cpEndPtr; char cHexValue[ 5 ]; char cBinaryResult; cHexValue[ 0 ] = '0'; cHexValue[ 1 ] = 'x'; cHexValue[ 2 ] = *cpRawUrl; cpRawUrl++; cHexValue[ 3 ] = *cpRawUrl; cHexValue[ 4 ] = 0; cBinaryResult = ( char ) strtol( cHexValue , &cpEndPtr , 0 ); return cBinaryResult; } short clCGISession::CGI_GetFormValues( char *cpRawUrl ) { char *cpReturnPointer; char *cpReturnPointer2; long lLoopX = 0; long lLoopY = 0; long lFieldNameLength = 0; long lFieldValueLength = 0; short sHexFlag = 0; if( !cpRawUrl ) return 0; cpReturnPointer2 = cpRawUrl; g_sCombinationNumber = CGI_GetNumberOfSets( cpRawUrl ); if( !g_sCombinationNumber ) return 0; for( lLoopX = 0 ; lLoopX < g_sCombinationNumber ; lLoopX++ ) { cpReturnPointer = cpRawUrl; lFieldNameLength = CGI_GetLengthBefore( cpRawUrl ); cpRawUrl += lFieldNameLength + ( g_sNumberOfHexPairs * 2 ) + 1; g_sNumberOfHexPairs = 0; lFieldValueLength = CGI_GetLengthBefore( cpRawUrl ); g_sNumberOfHexPairs = 0; stfeMainBlock[ lLoopX ].sm_cpFieldName = new char [ lFieldNameLength + 1 ]; if( !stfeMainBlock[ lLoopX ].sm_cpFieldName ) return 0; stfeMainBlock[ lLoopX ].sm_cpFieldValue = new char [ lFieldValueLength + 1 ]; if( !stfeMainBlock[ lLoopX ].sm_cpFieldValue ) return 0; memset( stfeMainBlock[ lLoopX ].sm_cpFieldName , 0 , lFieldNameLength + 1 ); memset( stfeMainBlock[ lLoopX ].sm_cpFieldValue , 0 , lFieldValueLength + 1 ); cpRawUrl = cpReturnPointer; for( lLoopY = 0 ; lLoopY < lFieldNameLength ; lLoopY++ ) { if( *cpRawUrl == CONST_CHEXIDENTIFIER ) { cpRawUrl++; stfeMainBlock[ lLoopX ].sm_cpFieldName[ lLoopY ] = CGI_ReturnHexValue( cpRawUrl ); if( stfeMainBlock[ lLoopX ].sm_cpFieldValue[ lLoopY ] == '~' ) stfeMainBlock[ lLoopX ].sm_cpFieldValue[ lLoopY ] = ' '; sHexFlag = 1; } else if( *cpRawUrl == '+' ) stfeMainBlock[ lLoopX ].sm_cpFieldName[ lLoopY ] = ' '; else if( *cpRawUrl == '~' ) stfeMainBlock[ lLoopX ].sm_cpFieldName[ lLoopY ] = ' '; else stfeMainBlock[ lLoopX ].sm_cpFieldName[ lLoopY ] = *cpRawUrl; cpRawUrl++; if( sHexFlag ) { cpRawUrl++; sHexFlag = 0; } } cpRawUrl++; for( lLoopY = 0 ; lLoopY < lFieldValueLength ; lLoopY++ ) { if( *cpRawUrl == CONST_CHEXIDENTIFIER ) { cpRawUrl++; stfeMainBlock[ lLoopX ].sm_cpFieldValue[ lLoopY ] = CGI_ReturnHexValue( cpRawUrl ); if( stfeMainBlock[ lLoopX ].sm_cpFieldValue[ lLoopY ] == '~' ) stfeMainBlock[ lLoopX ].sm_cpFieldValue[ lLoopY ] = ' '; sHexFlag = 1; } else if( *cpRawUrl == '+' ) stfeMainBlock[ lLoopX ].sm_cpFieldValue[ lLoopY ] = ' '; else if( *cpRawUrl == '~' ) stfeMainBlock[ lLoopX ].sm_cpFieldValue[ lLoopY ] = ' '; else stfeMainBlock[ lLoopX ].sm_cpFieldValue[ lLoopY ] = *cpRawUrl; cpRawUrl++; if( sHexFlag ) { cpRawUrl++; sHexFlag = 0; } } cpRawUrl++; } cpRawUrl = cpReturnPointer2; return 1; } short clCGISession::CGI_GetMethodType( void ) { char *cpRequestMethod; cpRequestMethod = getenv( "REQUEST_METHOD" ); if( cpRequestMethod != 0 ) { if( strcmp( cpRequestMethod , "GET" ) == 0 ) { g_sRequestMethod = 0; return 1; } if( strcmp( cpRequestMethod , "POST" ) == 0 ) { g_sRequestMethod = 1; return 1; } else { g_sRequestMethod = 2; return 0; } } g_sRequestMethod = 2; return 0; } char * clCGISession::CGI_GetRawUrl( void ) { long lContentLength; char *cpGetEnv; if( g_sRequestMethod == 0 ) { cpGetEnv = getenv( "QUERY_STRING" ); return cpGetEnv; } if( g_sRequestMethod == 1 ) { lContentLength = CGI_GetContentLength(); cpGetEnv = new char[ lContentLength + 1 ]; if( !cpGetEnv ) return 0; memset( cpGetEnv , 0 , lContentLength + 1 ); fread( cpGetEnv , lContentLength , 1 , stdin ); return cpGetEnv; } else { cpGetEnv = 0; return cpGetEnv; } } long clCGISession::CGI_GetContentLength( void ) { long lContentLength; char *cpEndPointer; char *cpContentLength; cpContentLength = getenv( "CONTENT_LENGTH" ); if( cpContentLength != 0 ) { if( g_sRequestMethod == 1 ) { lContentLength = strtol ( cpContentLength , &cpEndPointer , 0 ); return ( lContentLength ); } else return 0; } return 0; } -- __dj_shiny_blue____ Current Recommends:_ _____Coded Language - Krust______ ______ ____Don't stop - ATB ______ ____ __ __In and out of my life - OnePhatDeeva__ _ http://members.dencity.com/blahblur __