mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-05 10:40:42 +00:00
Clean up EDFInfo class to avoid memory leaks
This commit is contained in:
parent
0fd25f2f4e
commit
6624738f67
@ -32,13 +32,17 @@ EDFInfo::EDFInfo()
|
||||
datasize = 0;
|
||||
signalPtr = nullptr;
|
||||
hdrPtr = nullptr;
|
||||
fileData = nullptr;
|
||||
// fileData = nullptr;
|
||||
}
|
||||
|
||||
EDFInfo::~EDFInfo()
|
||||
{
|
||||
// if ( fileData )
|
||||
// delete fileData;
|
||||
// if ( fileData ) {
|
||||
if (fileData.size() > 0) {
|
||||
qDebug() << "EDFInfo destructor clearing fileData";
|
||||
fileData.clear();
|
||||
}
|
||||
// }
|
||||
|
||||
for (auto & s : edfsignals) {
|
||||
if (s.dataArray)
|
||||
@ -48,34 +52,35 @@ EDFInfo::~EDFInfo()
|
||||
// delete a;
|
||||
}
|
||||
|
||||
QByteArray * EDFInfo::Open(const QString & name)
|
||||
bool EDFInfo::Open(const QString & name)
|
||||
{
|
||||
if (hdrPtr != nullptr) {
|
||||
qWarning() << "EDFInfo::Open() called with file already open " << name;
|
||||
sleep(1);
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
QFile fi(name);
|
||||
if (!fi.open(QFile::ReadOnly)) {
|
||||
qDebug() << "EDFInfo::Open() Couldn't open file " << name;
|
||||
sleep(1);
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
fileData = new QByteArray();
|
||||
// fileData = new QByteArray();
|
||||
if (name.endsWith(STR_ext_gz)) {
|
||||
*fileData = gUncompress(fi.readAll()); // Open and decompress file
|
||||
fileData = gUncompress(fi.readAll()); // Open and decompress file
|
||||
} else {
|
||||
*fileData = fi.readAll(); // Open and read uncompressed file
|
||||
fileData = fi.readAll(); // Open and read uncompressed file
|
||||
}
|
||||
fi.close();
|
||||
if (fileData->size() <= EDFHeaderSize) {
|
||||
fileData->clear();;
|
||||
if (fileData.size() <= EDFHeaderSize) {
|
||||
fileData.clear();;
|
||||
qDebug() << "EDFInfo::Open() File too short " << name;
|
||||
sleep(1);
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
filename = name;
|
||||
return fileData;
|
||||
// return fileData;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EDFInfo::parseHeader( EDFHeaderRaw *hdrPtr )
|
||||
@ -85,8 +90,8 @@ bool EDFInfo::parseHeader( EDFHeaderRaw *hdrPtr )
|
||||
edfHdr.version = QString::fromLatin1(hdrPtr->version, 8).toLong(&ok);
|
||||
if (!ok) {
|
||||
qWarning() << "EDFInfo::Parse() Bad Version " << filename;
|
||||
sleep(1);
|
||||
fileData->clear();
|
||||
// sleep(1);
|
||||
fileData.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -104,48 +109,47 @@ bool EDFInfo::parseHeader( EDFHeaderRaw *hdrPtr )
|
||||
edfHdr.num_header_bytes = QString::fromLatin1(hdrPtr->num_header_bytes, 8).toLong(&ok);
|
||||
if (!ok) {
|
||||
qWarning() << "EDFInfo::Parse() Bad header byte count " << filename;
|
||||
sleep(1);
|
||||
fileData->clear();
|
||||
// sleep(1);
|
||||
fileData.clear();
|
||||
return false;
|
||||
}
|
||||
edfHdr.reserved44=QString::fromLatin1(hdrPtr->reserved, 44).trimmed();
|
||||
edfHdr.num_data_records = QString::fromLatin1(hdrPtr->num_data_records, 8).toLong(&ok);
|
||||
if (!ok) {
|
||||
qWarning() << "EDFInfo::Parse() Bad data record count " << filename;
|
||||
sleep(1);
|
||||
fileData->clear();
|
||||
// sleep(1);
|
||||
fileData.clear();
|
||||
return false;
|
||||
}
|
||||
edfHdr.duration_Seconds = QString::fromLatin1(hdrPtr->dur_data_records, 8).toDouble(&ok);
|
||||
if (!ok) {
|
||||
qWarning() << "EDFInfo::Parse() Bad duration " << filename;
|
||||
sleep(1);
|
||||
fileData->clear();
|
||||
// sleep(1);
|
||||
fileData.clear();
|
||||
return false;
|
||||
}
|
||||
edfHdr.num_signals = QString::fromLatin1(hdrPtr->num_signals, 4).toLong(&ok);
|
||||
if (!ok) {
|
||||
qWarning() << "EDFInfo::Parse() Bad number of signals " << filename;
|
||||
sleep(1);
|
||||
fileData->clear();
|
||||
// sleep(1);
|
||||
fileData.clear();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EDFInfo::Parse(QByteArray * fileData )
|
||||
{
|
||||
bool EDFInfo::Parse() {
|
||||
bool ok;
|
||||
|
||||
if (fileData == nullptr) {
|
||||
if (fileData.size() == 0) {
|
||||
qWarning() << "EDFInfo::Parse() called without valid EDF data " << filename;
|
||||
sleep(1);
|
||||
// sleep(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
hdrPtr = (EDFHeaderRaw *)(*fileData).constData();
|
||||
signalPtr = (char *)(*fileData).constData() + EDFHeaderSize;
|
||||
filesize = (*fileData).size();
|
||||
hdrPtr = (EDFHeaderRaw *)fileData.constData();
|
||||
signalPtr = (char *)fileData.constData() + EDFHeaderSize;
|
||||
filesize = fileData.size();
|
||||
datasize = filesize - EDFHeaderSize;
|
||||
pos = 0;
|
||||
|
||||
@ -167,7 +171,7 @@ bool EDFInfo::Parse(QByteArray * fileData )
|
||||
if (eof) {
|
||||
qWarning() << "EDFInfo::Parse() Early end of file " << filename;
|
||||
sleep(1);
|
||||
fileData->clear();
|
||||
fileData.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -204,8 +208,8 @@ bool EDFInfo::Parse(QByteArray * fileData )
|
||||
// could do it earlier, but it won't crash from > EOF Reads
|
||||
if (eof) {
|
||||
qWarning() << "EDFInfo::Parse() Early end of file " << filename;
|
||||
sleep(1);
|
||||
fileData->clear();
|
||||
// sleep(1);
|
||||
fileData.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -220,8 +224,8 @@ bool EDFInfo::Parse(QByteArray * fileData )
|
||||
// Space required more than the remainder left to read,
|
||||
// so abort and let the user clean up the corrupted file themselves
|
||||
qWarning() << "EDFInfo::Parse(): " << filename << " is too short!";
|
||||
sleep(1);
|
||||
fileData->clear();
|
||||
// sleep(1);
|
||||
fileData.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -248,7 +252,7 @@ bool EDFInfo::Parse(QByteArray * fileData )
|
||||
}
|
||||
}
|
||||
}
|
||||
fileData->clear();
|
||||
fileData.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -260,20 +264,20 @@ EDFHeaderQT * EDFInfo::GetHeader( const QString & name)
|
||||
sleep(1);
|
||||
return nullptr;
|
||||
}
|
||||
fileData = new QByteArray();
|
||||
// fileData = new QByteArray();
|
||||
if (name.endsWith(STR_ext_gz)) {
|
||||
*fileData = gUncompress(fi.read(sizeof(EDFHeaderRaw))); // Open and decompress file
|
||||
fileData = gUncompress(fi.read(sizeof(EDFHeaderRaw))); // Open and decompress file
|
||||
} else {
|
||||
*fileData = fi.read(sizeof(EDFHeaderRaw)); // Open and read uncompressed file
|
||||
fileData = fi.read(sizeof(EDFHeaderRaw)); // Open and read uncompressed file
|
||||
}
|
||||
fi.close();
|
||||
filename = name;
|
||||
hdrPtr = (EDFHeaderRaw *)(*fileData).constData();
|
||||
hdrPtr = (EDFHeaderRaw *)fileData.constData();
|
||||
|
||||
if ( ! parseHeader( hdrPtr ) )
|
||||
return nullptr;
|
||||
|
||||
fileData->clear();
|
||||
fileData.clear();
|
||||
return & edfHdr;
|
||||
}
|
||||
|
||||
|
@ -120,9 +120,9 @@ class EDFInfo
|
||||
|
||||
virtual ~EDFInfo();
|
||||
|
||||
virtual QByteArray * Open(const QString & name); //! \brief Open the EDF+ file, and read it's header
|
||||
virtual bool Open(const QString & name); //! \brief Open the EDF+ file, and read it's header
|
||||
|
||||
virtual bool Parse(QByteArray * fileData); //! \brief Parse the EDF+ file into the EDFheaderQT. Must call Open(..) first.
|
||||
virtual bool Parse(); //! \brief Parse the EDF+ file into the EDFheaderQT. Must call Open(..) first.
|
||||
|
||||
virtual bool parseHeader( EDFHeaderRaw * hdrPtr ); //! \brief parse just the edf header for duration, etc
|
||||
|
||||
@ -161,7 +161,7 @@ class EDFInfo
|
||||
qint16 Read16(); //! \brief Read 16 bit word of data from the EDF+ data stream
|
||||
|
||||
//! \brief This is the array holding the EDF file data
|
||||
QByteArray * fileData;
|
||||
QByteArray fileData;
|
||||
//! \brief The EDF+ files header structure, used as a place holder while processing the text data.
|
||||
EDFHeaderRaw *hdrPtr;
|
||||
//! \brief This is the array of signal descriptors and values
|
||||
|
@ -28,9 +28,9 @@
|
||||
ResMedEDFInfo::ResMedEDFInfo() :EDFInfo() { }
|
||||
ResMedEDFInfo::~ResMedEDFInfo() { }
|
||||
|
||||
bool ResMedEDFInfo::Parse(QByteArray * fileData ) // overrides and calls the super's Parse
|
||||
bool ResMedEDFInfo::Parse( ) // overrides and calls the super's Parse
|
||||
{
|
||||
EDFInfo::Parse( fileData );
|
||||
EDFInfo::Parse( );
|
||||
|
||||
// Now massage some stuff into OSCAR's layout
|
||||
int snp = edfHdr.recordingident.indexOf("SRN=");
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
ResMedEDFInfo();
|
||||
~ResMedEDFInfo();
|
||||
|
||||
virtual bool Parse(QByteArray * fileData) override; // overrides and calls the super's Parse
|
||||
virtual bool Parse() override; // overrides and calls the super's Parse
|
||||
|
||||
virtual qint64 GetDurationMillis() { return dur_data_record; } // overrides the super
|
||||
|
||||
|
@ -434,8 +434,12 @@ int ResmedLoader::Open(const QString & dirpath)
|
||||
continue;
|
||||
|
||||
ResMedEDFInfo * stredf = new ResMedEDFInfo();
|
||||
QByteArray * fileData = stredf->Open(fi.canonicalFilePath() );
|
||||
if (!stredf->Parse(fileData)) {
|
||||
if ( stredf->Open(fi.canonicalFilePath() ) ) {
|
||||
qDebug() << "Failed to open" << filename;
|
||||
delete stredf;
|
||||
continue;
|
||||
}
|
||||
if (!stredf->Parse()) {
|
||||
qDebug() << "Faulty STR file" << filename;
|
||||
delete stredf;
|
||||
continue;
|
||||
@ -1407,8 +1411,11 @@ void BackupSTRfiles( const QString path, const QString strBackupPath, MachineInf
|
||||
// Now place any of these files in the Backup folder sorted by the file date
|
||||
for (auto & filename : strfiles) {
|
||||
ResMedEDFInfo * stredf = new ResMedEDFInfo();
|
||||
QByteArray * fileData = stredf->Open(filename);
|
||||
if ( ! stredf->Parse(fileData)) {
|
||||
if ( ! stredf->Open(filename) ) {
|
||||
qDebug() << "Failed to open" << filename;
|
||||
continue;
|
||||
}
|
||||
if ( ! stredf->Parse()) {
|
||||
qDebug() << "Faulty STR file" << filename;
|
||||
delete stredf;
|
||||
continue;
|
||||
@ -1456,6 +1463,7 @@ void BackupSTRfiles( const QString path, const QString strBackupPath, MachineInf
|
||||
QFile::exists(gzfile) && QFile::remove(gzfile);
|
||||
|
||||
STRmap[date] = STRFile(backupfile, stredf);
|
||||
// delete stredf;
|
||||
} // end for walking the STR files list
|
||||
}
|
||||
|
||||
@ -2128,15 +2136,21 @@ bool ResmedLoader::LoadCSL(Session *sess, const QString & path)
|
||||
#endif
|
||||
|
||||
ResMedEDFInfo edf;
|
||||
QByteArray * fileData = edf.Open(path);
|
||||
if ( ! edf.Open(path) ) {
|
||||
qDebug() << "LoadCSL failed to open" << path;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfopentime = time.elapsed();
|
||||
time.start();
|
||||
#endif
|
||||
|
||||
if (!edf.Parse(fileData))
|
||||
if (!edf.Parse()) {
|
||||
qDebug() << "LoadCSL failed to parse" << path;
|
||||
// fileData->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfparsetime = time.elapsed();
|
||||
@ -2183,6 +2197,8 @@ bool ResmedLoader::LoadCSL(Session *sess, const QString & path)
|
||||
qDebug() << "Unfinished csr event in " << edf.filename;
|
||||
}
|
||||
|
||||
// fileData->clear();
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
timeMutex.lock();
|
||||
timeInLoadCSL += time.elapsed();
|
||||
@ -2201,13 +2217,21 @@ bool ResmedLoader::LoadEVE(Session *sess, const QString & path)
|
||||
time.start();
|
||||
#endif
|
||||
ResMedEDFInfo edf;
|
||||
QByteArray * fileData = edf.Open(path);
|
||||
if ( ! edf.Open(path) ) {
|
||||
qDebug() << "LoadEVE failed to open" << path;
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfopentime = time.elapsed();
|
||||
time.start();
|
||||
#endif
|
||||
if (!edf.Parse(fileData))
|
||||
|
||||
if (!edf.Parse()) {
|
||||
qDebug() << "LoadEVE failed to parse" << path;
|
||||
// fileData->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfparsetime = time.elapsed();
|
||||
time.start();
|
||||
@ -2270,6 +2294,8 @@ bool ResmedLoader::LoadEVE(Session *sess, const QString & path)
|
||||
}
|
||||
}
|
||||
|
||||
// fileData->clear();
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
timeMutex.lock();
|
||||
timeInLoadEVE += time.elapsed();
|
||||
@ -2288,13 +2314,19 @@ bool ResmedLoader::LoadBRP(Session *sess, const QString & path)
|
||||
time.start();
|
||||
#endif
|
||||
ResMedEDFInfo edf;
|
||||
QByteArray * fileData = edf.Open(path);
|
||||
if ( ! edf.Open(path) ) {
|
||||
qDebug() << "LoadBRP failed to open" << path;
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfopentime = time.elapsed();
|
||||
time.start();
|
||||
#endif
|
||||
if (!edf.Parse(fileData))
|
||||
if (!edf.Parse()) {
|
||||
qDebug() << "LoadBRP failed to parse" << path;
|
||||
// fileData->clear();
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfparsetime = time.elapsed();
|
||||
time.start();
|
||||
@ -2359,6 +2391,8 @@ bool ResmedLoader::LoadBRP(Session *sess, const QString & path)
|
||||
}
|
||||
}
|
||||
|
||||
// fileData->clear();
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
timeMutex.lock();
|
||||
timeInLoadBRP += time.elapsed();
|
||||
@ -2380,15 +2414,21 @@ bool ResmedLoader::LoadSAD(Session *sess, const QString & path)
|
||||
#endif
|
||||
|
||||
ResMedEDFInfo edf;
|
||||
QByteArray * fileData = edf.Open(path);
|
||||
if ( ! edf.Open(path) ) {
|
||||
qDebug() << "LoadSAD failed to open" << path;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfopentime = time.elapsed();
|
||||
time.start();
|
||||
#endif
|
||||
|
||||
if (!edf.Parse(fileData))
|
||||
if (!edf.Parse()) {
|
||||
qDebug() << "LoadSAD failed to parse" << path;
|
||||
// fileData->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfparsetime = time.elapsed();
|
||||
@ -2431,6 +2471,8 @@ bool ResmedLoader::LoadSAD(Session *sess, const QString & path)
|
||||
}
|
||||
}
|
||||
|
||||
// fileData->clear();
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
timeMutex.lock();
|
||||
timeInLoadSAD += time.elapsed();
|
||||
@ -2449,13 +2491,21 @@ bool ResmedLoader::LoadPLD(Session *sess, const QString & path)
|
||||
time.start();
|
||||
#endif
|
||||
ResMedEDFInfo edf;
|
||||
QByteArray * fileData = edf.Open(path);
|
||||
if ( ! edf.Open(path) ) {
|
||||
qDebug() << "LoadPLD failed to open" << path;
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfopentime = time.elapsed();
|
||||
time.start();
|
||||
#endif
|
||||
if (!edf.Parse(fileData))
|
||||
|
||||
if (!edf.Parse()) {
|
||||
qDebug() << "LoadPLD failed to parse" << path;
|
||||
// fileData->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
int edfparsetime = time.elapsed();
|
||||
time.start();
|
||||
@ -2596,6 +2646,9 @@ bool ResmedLoader::LoadPLD(Session *sess, const QString & path)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// fileData->clear();
|
||||
|
||||
#ifdef DEBUG_EFFICIENCY
|
||||
timeMutex.lock();
|
||||
timeInLoadPLD += time.elapsed();
|
||||
|
Loading…
Reference in New Issue
Block a user