Dear all,
I have the following problem: I made a class (CDatabase) with some
simple methods. The one I use to return the queries results is the
following:
Result CDatabase::ReturnQuery(string query)
{
try
{
//executes a query and returns a resultset back
Query myQuery = myConn.query();
myQuery.reset();
//sets the query text
myQuery << query;
//executes the query
Result myResult = myQuery.store();
return myResult;
}
catch (BadQuery er)
{
cout << "DB error: " << er.error << endl;
return NULL;
}
}
In the main class of the program I have a call to the global CDatabase
object (myDB) as the following:
bool CCheckThread::Check()
{
//check if there is a new record on the DB
Result myResult;
myResult = myDB.ReturnQuery("select id from task where status_id =
0;");
if(myResult.size()>0)
{
Result::iterator myCounter;
Row myRow;
//for every record found we launch a CSessionThread which
is going to handle it
for
(myCounter=myResult.begin();myCounter!=myResult.end();myCounter++)
{
if(!myShutdown)
{
//logs that the new session was found
pthread_mutex_lock(&myLogMutex);
myLog.WriteLog("I", "A new session was
found. Starting analysis");
pthread_mutex_unlock(&myLogMutex);
myRow = *myCounter;
long myId = (long) myRow[0];
if(pthread_create(&myTaskThread_t, NULL,
&StartTaskThread, &myId)==0)
{
myThreadNumber++;
//sleeps 2 seconds in order to let
the thread start
sleep(2);
}
else
{
pthread_mutex_lock(&myLogMutex);
myLog.WriteLog("E", "Could not
create CSessionThread");
pthread_mutex_unlock(&myLogMutex);
}
}
}
return true;
}
else
return false;
}
The problem is that whenever I have no records found, when the function
ends I have a segmentation fault with the following message "*** glibc
detected *** double free or corruption: ". If records are found no
problems. I am wondering where the problem could be, even debbuged via
xxgdb.
I checked for the previuos messages but haven't found anything about this.
Could you please help me out ?
Regards
Fabio