First-chance exception at ...: Access violation reading location ... when debugging using Visual Studio 2010

3

I try so hard to catch from legacy code access violation keep getting :

First-chance exception at 0x57e77e1c in YouTubeLocal.exe: 0xC0000005: Access violation reading location 0x0000000c.

My stack looks like this:

    Qt5Guid.dll!57e77e1c()  
    [Frames below may be incorrect and/or missing, no symbols loaded for Qt5Guid.dll]   
    Qt5Guid.dll!57e75604()  
    Qt5Guid.dll!57ed520b()  
    Qt5Guid.dll!57dcf18b()  
>   msvcr100d.dll!_unlock(int locknum=0x00000004)  Line 375 C
    msvcr100d.dll!_heap_alloc_dbg_impl(unsigned int nSize=0x00000040, int nBlockUse=0x00000001, const char * szFileName=0x00000000, int nLine=0x00000000, int * errno_tmp=0x0015cb70)  Line 507 + 0x7 bytes C++
    msvcr100d.dll!_heap_alloc_dbg_impl(unsigned int nSize=0x00000040, int nBlockUse=0x00000001, const char * szFileName=0x00000000, int nLine=0x00000000, int * errno_tmp=0x0015cb70)  Line 504 + 0xc bytes C++
    msvcr100d.dll!_nh_malloc_dbg_impl(unsigned int nSize=0x00000040, int nhFlag=0x00000000, int nBlockUse=0x00000001, const char * szFileName=0x00000000, int nLine=0x00000000, int * errno_tmp=0x0015cb70)  Line 239 + 0x19 bytes  C++
    msvcr100d.dll!_nh_malloc_dbg(unsigned int nSize=0x00000002, int nhFlag=0x0015cbdc, int nBlockUse=0x0015cbc8, const char * szFileName=0x0015cbb0, int nLine=0x0015cbc8)  Line 302 + 0x1d bytes   C++
    Qt5Cored.dll!533b0628()     
    Qt5Cored.dll!53388046()     
    Qt5Cored.dll!5335f56b()     
    Qt5Cored.dll!535e74c4()     
    Qt5Cored.dll!536f7198()     
    Qt5Widgetsd.dll!53aa4aea()  
    kernel32.dll!778bc3d4()     
    msvcr100d.dll!_unlock(int locknum=0x00000004)  Line 375 C
    msvcr100d.dll!_free_dbg(void * pUserData=0x53a4b300, int nBlockUse=0x019757a0)  Line 1270 + 0x7 bytes   C++
    msvcr100d.dll!_free_dbg(void * pUserData=0x53a4b300, int nBlockUse=0x019757a0)  Line 1267 + 0xc bytes   C++
    01b4bd40()  
    kernel32.dll!778bc3d4()     
    msvcr100d.dll!_free_base(void * pBlock=0x0015d060)  Line 50 + 0x13 bytes    C
    018a4a84()  
    kernel32.dll!778bc3d4()     
    msvcr100d.dll!_free_base(void * pBlock=0x57c49736)  Line 50 + 0x13 bytes    C
    0015d140()  
    feeefeee()  

The debugger is stopping in this file (mlock.c)

/***
* _unlock - Release multi-thread lock
*
*Purpose:
*       Note that it is legal for a thread to aquire _EXIT_LOCK1
*       multiple times.
*
*Entry:
*       locknum = number of the lock to release
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/

void __cdecl _unlock (
        int locknum
        )
{
        /*
         * leave the critical section.
         */
        LeaveCriticalSection( _locktable[locknum].lock );
}

I cannot find the line where the access violation occurs. How can I catch the line that is causing the exception?

UPDATE:
this is the solution for me : Microsoft Application Verifier

c++
visual-studio-2010
thread-safety
access-violation
asked on Stack Overflow Feb 24, 2013 by user63898 • edited Feb 2, 2014 by Shog9

1 Answer

0

Try adding some macro that will set pointer to NULL just after releasing the memory. Also try adding some asserts or similar just before you use such pointers. With that you should be able to locate the bug pretty fast.

answered on Stack Overflow May 10, 2013 by user1764961

User contributions licensed under CC BY-SA 3.0