Unprocessed exception: 0xc0000005: Access conflict when the read location is 0 xfeeefeee

Source: Internet
Author: User
Tags sleep function
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.