Error message:
An access conflict occurs when 0x1004a498 (commutil. dll) in commconsoleserver.exe is not handled: 0xc0000005: The read location is 0 xfeeefeee.
Error analysis:
This error is generally caused by access to memory that should not be accessed. During the release of heap memory space, the heapfree function uses 0xfeeefeee
The memory is marked to indicate that the memory is idle. That is to say, the memory accessed through this pointer does not actually belong to you. An error is reported.
Source:
In the following code,
Int _ tmain (INT argc, _ tchar * argv []) {_ crtsetdbgflag (_ crtdbg_report_flag | _ crtdbg_leak_check_df); _ crtsetbreakalloc (150); // start the service thread, listen and establish the connection psrvthread = new serverthread (); psrvthread-> Start (); //: Sleep (1000); psrvthread-> stop (); Delete psrvthread; _ crtdumpmemoryleaks (); Return 0 ;}
The preceding problems may occur sometimes, but the sleep (1000) statement will not. Therefore, a breakpoint is added to the start function for tracking. The problem was found.
The START function is as follows:
Void thread: Start () {m_hthread =: createthread (null, 0, _ thd_start, this, 0, & m_threadid); // run immediately after the thread is created}
Extern unsigned long _ stdcall _ thd_start (void * PARAM) // The thread function definition has fixed rules {return (long) (thread *) PARAM) -> Run ();}
Error analysis:
If there is no sleep function, this will happen according to the debug process. After I delete the psrvthread, the thread starts the function. A problem occurs. The parameter passed in the Start function is the this pointer, but after the delete operation, the space indicated by this pointer has been released, so this pointer is invalid, if you call the run function of an object through it, an error is returned.