Fix Valgrind report at End of RS

XXXX bytes in XX blocks are still reachable in loss record.
This commit is contained in:
Phenom 2020-11-26 19:13:54 +01:00
parent 1ee38877ca
commit 3fff0869a2

View File

@ -709,44 +709,46 @@ void RsGxsDataAccess::processRequests()
while (!mRequestQueue.empty()) while (!mRequestQueue.empty())
{ {
// Extract the first elements from the request queue. cleanup all other elements marked at terminated. // Extract the first elements from the request queue. cleanup all other elements marked at terminated.
GxsRequest* req = nullptr; GxsRequest* req = nullptr;
{ {
RsStackMutex stack(mDataMutex); /******* LOCKED *******/ RsStackMutex stack(mDataMutex); /******* LOCKED *******/
rstime_t now = time(nullptr); // this is ok while in the loop below rstime_t now = time(nullptr); // this is ok while in the loop below
while(!mRequestQueue.empty() && req == nullptr) while(!mRequestQueue.empty() && req == nullptr)
{ {
if(now > mRequestQueue.begin()->second->reqTime + MAX_REQUEST_AGE) if(now > mRequestQueue.begin()->second->reqTime + MAX_REQUEST_AGE)
{ {
delete mRequestQueue.begin()->second;
mRequestQueue.erase(mRequestQueue.begin()); mRequestQueue.erase(mRequestQueue.begin());
continue; continue;
} }
switch( mRequestQueue.begin()->second->status ) switch( mRequestQueue.begin()->second->status )
{ {
case PARTIAL: case PARTIAL:
RsErr() << "Found partial request in mRequestQueue. This is a bug." << std::endl; // fallthrough RsErr() << "Found partial request in mRequestQueue. This is a bug." << std::endl; // fallthrough
case COMPLETE: case COMPLETE:
case DONE: case DONE:
case FAILED: case FAILED:
case CANCELLED: case CANCELLED:
#ifdef DATA_DEBUG #ifdef DATA_DEBUG
RsDbg() << " request " << mRequestQueue.begin()->second->token << ": status = " << mRequestQueue.begin()->second->status << ": removing from the RequestQueue" << std::endl; RsDbg() << " request " << mRequestQueue.begin()->second->token << ": status = " << mRequestQueue.begin()->second->status << ": removing from the RequestQueue" << std::endl;
#endif #endif
mRequestQueue.erase(mRequestQueue.begin()); delete mRequestQueue.begin()->second;
continue; mRequestQueue.erase(mRequestQueue.begin());
break; continue;
case PENDING: break;
req = mRequestQueue.begin()->second; case PENDING:
req->status = PARTIAL; req = mRequestQueue.begin()->second;
mRequestQueue.erase(mRequestQueue.begin()); // remove it right away from the waiting queue. req->status = PARTIAL;
break; mRequestQueue.erase(mRequestQueue.begin()); // remove it right away from the waiting queue.
} break;
}
} }
} } // END OF MUTEX.
if (!req) if (!req)
break; break;
@ -813,33 +815,33 @@ void RsGxsDataAccess::processRequests()
else else
RsErr() << __PRETTY_FUNCTION__ << " Failed to process request, token: " << req->token << std::endl; RsErr() << __PRETTY_FUNCTION__ << " Failed to process request, token: " << req->token << std::endl;
// We cannot easily remove the request here because the queue may have more elements now and mRequestQueue.begin() is not necessarily the same element. // We cannot easily remove the request here because the queue may have more elements now and mRequestQueue.begin() is not necessarily the same element.
// but we mark it as COMPLETE/FAILED so that it will be removed in the next loop. // but we mark it as COMPLETE/FAILED so that it will be removed in the next loop.
{ {
RsStackMutex stack(mDataMutex); /******* LOCKED *******/ RsStackMutex stack(mDataMutex); /******* LOCKED *******/
if(ok) if(ok)
{ {
// When the request is complete, we move it to the complete list, so that the caller can easily retrieve the request data // When the request is complete, we move it to the complete list, so that the caller can easily retrieve the request data
#ifdef DATA_DEBUG #ifdef DATA_DEBUG
RsDbg() << " Request completed successfully. Marking as COMPLETE." << std::endl; RsDbg() << " Request completed successfully. Marking as COMPLETE." << std::endl;
#endif #endif
req->status = COMPLETE ; req->status = COMPLETE ;
mCompletedRequests[req->token] = req; mCompletedRequests[req->token] = req;
mPublicToken[req->token] = COMPLETE; mPublicToken[req->token] = COMPLETE;
} }
else else
{ {
req->status = FAILED; req->status = FAILED;
mPublicToken[req->token] = FAILED; mPublicToken[req->token] = FAILED;
#ifdef DATA_DEBUG #ifdef DATA_DEBUG
RsDbg() << " Request failed. Marking as FAILED." << std::endl; RsDbg() << " Request failed. Marking as FAILED." << std::endl;
#endif #endif
} }
} } // END OF MUTEX.
} // END OF MUTEX. }
} }