Reputation: 145
With this code :
bool initQdbgLog()
{
deleteOldLogs(); //delete old log files
initLogFileName(); //create the logfile name
QFile outFile (logFileName);
if (outFile.open (QIODevice::WriteOnly | QIODevice::Append)) { <<<<<<<<<<<<<(1)
qInstallMsgHandler (QDBGLOG::myMessageHandler);
return true; <<<<<<<<<<<<<(2)
} else {
return false;
}
}
Klocwork signals an Resource leak :
Resource acquired to '@temp_3' at line <<<(1) may be lost here <<<(2)
Someone knows why ?
@Sivanesh Waran Hello thanks for your help, but I tried different code and always got the same error, even with that code:
void initQdbgLog()
{
deleteOldLogs(); //delete old log files
initLogFileName(); //create the logfile name
QFile outFile (logFileName);
bool result = outFile.open (QIODevice::WriteOnly | QIODevice::Append);
if (result) {
qInstallMsgHandler (QDBGLOG::myMessageHandler);
outFile.close();
}
}
Upvotes: 1
Views: 1109
Reputation: 76
There are situations in which resources are limited, and if a resource isn't properly released, it will be unavailable at the next access attempt.
Resource acquired at to (QIODevice::WriteOnly | QIODevice::Append) at line number 6 will be lost at line number 12 and 14. but they are not released properly So Klocwork will show Resource leak warning here.
The RH.LEAK checker of Klocwork finds instances in which all descriptors related to a previously acquired, but unreleased, resource are lost.
Upvotes: 0