我是C編程新手。我使用visual studio 2010以C++代碼運行CPLEX庫。執行某些操作時,我遇到訪問衝突。使用VSLEX使用CPLEX訪問衝突寫入位置
在CRT文件mlock.c中定義的函數void __cdecl _unlock中報告違規。特定行是LeaveCriticalSection(_locktable [locknum] .lock);.
錯誤消息是在0x0f63443b未處理的異常:0xC0000005:訪問衝突寫入位置0xeb43c7c4。我的解釋是這是一個記憶相關的問題,但我不確定。另外,我不知道如何跟蹤代碼中的內存塊0xeb43c7c4。
下面是調用堆棧:
cplex124.dll!0fdd443b()
[Frames below may be incorrect and/or missing, no symbols loaded for cplex124.dll]
cplex124.dll!0fdd3bbb()
cplex124.dll!0fcd0610()
cplex124.dll!0fccfbfd()
cplex124.dll!0feb70fd()
cplex124.dll!0fede883()
> name.exe!_unlock(int locknum) Line 375 C
name.exe!_unlock_file2(int i, void * s) Line 356 + 0x9 bytes C
name.exe!printf(const char * format, ...) Line 68 + 0x10 bytes C
name.exe!main(int argc, char * * argv) Line 620 + 0xe bytes C++
name.exe!__tmainCRTStartup() Line 278 + 0x12 bytes C
kernel32.dll!7693ed6c()
ntdll.dll!7701377b()
ntdll.dll!7701374e()
爲_unlock的來源是在mlock.c文件:
void __cdecl _unlock (
int locknum
)
{
/*
* leave the critical section.
*/
LeaveCriticalSection(_locktable[locknum].lock);
}
#ifdef _M_IX86
#pragma optimize("y",on)
#endif /* _M_IX86 */
而且來源的printf是在文件printf.c爲:
int __cdecl printf (
const char *format,
...
)
/*
* stdout 'PRINT', 'F'ormatted
*/
{
va_list arglist;
int buffing;
int retval;
_VALIDATE_RETURN((format != NULL), EINVAL, -1);
va_start(arglist, format);
_lock_str2(1, stdout);
__try {
buffing = _stbuf(stdout);
retval = _output_l(stdout,format,NULL,arglist);
_ftbuf(buffing, stdout);
}
__finally {
_unlock_str2(1, stdout);
}
return(retval);
}
如果我刪除了演唱會的文件中的鏈接項目屬性,我得到同樣的錯誤消息,但在日e文件tidtable.c,在_CRTIMP PFLS_GETVALUE_FUNCTION __cdecl __set_flsgetvalue()行中:PFLS_GETVALUE_FUNCTION flsGetValue = FLS_GETVALUE;
我將不勝感激任何意見。
謝謝。
你能否提供你的源代碼,尤其是'_unlock'方法和調用'printf'的代碼? – leander 2013-05-06 00:47:46
我在問題中添加了來源。 – user1372020 2013-05-06 01:40:40
在調用庫代碼之前,您可能會破壞堆棧或代碼堆。你應該看看你的代碼和你引用的「一些行爲」。 – 2013-05-06 18:54:33