Memory Access Violation While Using PQexec
I encounter case when I call a stored procedure for 299166 th times (intensive, i put a non-stop while true loop to call stored procedure)
, the following exception will be thrown from PQexec. I am rather sure the exception are from PQexec, as there is a just before cout and just after cout wrap around PQexec.
std::cout << "Start PQexec " << sql << std::endl;
PGresult *res = PQexec(connection, sql.c_str());
std::cout << "End PQexec " << sql << std::endl;
const bool status = (PQresultStatus(res) == PGRES_TUPLES_OK);
PQclear(res);
"End PQexec..." is not being printed.
The last printed message before crashed is :
Start PQexec SELECT * FROM insert_unit(1,299166,array[0.407461,0.516022,0.434267
,0.802882,-1,1.99054,1.99039,0.808687], array['Pad Area','Pad Pitch','Pad Width','Pad Length','Side Pad Pitch','Package X Dimension','Package Y Dimension','Package Z Dimension'], array['mm','mm','mm','mm','mm','mm','mm','mm'])
The output is :
The thread 'Win32 Thread' (0x264) has exited with code 0 (0x0).
First-chance exception at 0x7c812afb in Report.exe: Microsoft C++ exception: std::exception at memory location 0x0012edb4..
First-chance exception at 0x7c812afb in Report.exe: Microsoft C++ exception: std::exception at memory location 0x0012ed94..
First-chance exception at 0x10017ea5 in Report.exe: 0xC0000005: Access violation writing location 0xfeeefeee.
'Report.exe': Unloaded 'C:\WINDOWS\system32\wshtcpip.dll'
'Report.exe': Unloaded 'C:\WINDOWS\system32\hnetcfg.dll'
Unhandled exception at 0x10017ea5 in Report.exe: 0xC0000005: Access violation writing location 0xfeeefeee.
The call stack is :
libpq.dll!10017ea5()
[Frames below may be incorrect and/or missing, no symbols loaded for libpq.dll]
libpq.dll!1000fa61()
msvcr90d.dll!__set_flsgetvalue() Line 256 + 0xc bytes C
msvcp90d.dll!std::clog() + 0x3f bytes C++
Using VC 2008, I break at file tidtable.c
_CRTIMP PFLS_GETVALUE_FUNCTION __cdecl __set_flsgetvalue()
{
#ifdef _M_IX86
PFLS_GETVALUE_FUNCTION flsGetValue = FLS_GETVALUE; <-- BREAK HERE
if (!flsGetValue)
{
flsGetValue = _decode_pointer(gpFlsGetValue);
TlsSetValue(__getvalueindex, flsGetValue);
}
return flsGetValue;
#else /* _M_IX86 */
Any suggestion?
On 14/01/2010 4:49 PM, Yan Cheng Cheok wrote:
I encounter case when I call a stored procedure for 299166 th times (intensive, i put a non-stop while true loop to call stored procedure)
, the following exception will be thrown from PQexec. I am rather sure the exception are from PQexec, as there is a just before cout and just after cout wrap around PQexec.
std::cout<< "Start PQexec "<< sql<< std::endl;
PGresult *res = PQexec(connection, sql.c_str());
std::cout<< "End PQexec "<< sql<< std::endl;
const bool status = (PQresultStatus(res) == PGRES_TUPLES_OK);
PQclear(res);"End PQexec..." is not being printed.
The call stack is :libpq.dll!10017ea5()
[Frames below may be incorrect and/or missing, no symbols loaded for libpq.dll]
You need to add c:\Program Files\PostgreSQL\8.4\symbols to your debug
symbol path. See:
http://wiki.postgresql.org/wiki/Getting_a_stack_trace_of_a_running_PostgreSQL_backend_on_Windows
That will also help Visual Studio break accurately, which it probably
isn't doing right now. There's a fair chance that where you broke in the
debugger has nothing to do with what is actually wrong.
Any suggestion?
I'm too clueless to give you a useful answer here, beyond telling you to
set your debug environment up properly and try again.
If you can extract this into a standalone test case (a single compilable
C or C++ program, plus a .sql file) that'd be rather handy, though. It
also means that if it's a bug in your code - say, you're corrupting the
heap - then building a test case will help you track that down by
elimination.
--
Craig Ringer