Updated corrupted file reading error management, make memory unit-tests more stable.
if (aFileVer >= TDocStd_FormatVersion_VERSION_3) {
BinLDrivers_DocumentSection aSection;
do {
- BinLDrivers_DocumentSection::ReadTOC (aSection, theIStream, aFileVer);
+ if (!BinLDrivers_DocumentSection::ReadTOC (aSection, theIStream, aFileVer))
+ break;
mySections.Append(aSection);
} while (!aSection.Name().IsEqual (aQuickPart ? ENDSECTION_POS : SHAPESECTION_POS) && !theIStream.eof());
- if (theIStream.eof()) {
+ if (mySections.IsEmpty() || theIStream.eof()) {
// There is no shape section in the file.
myMsgDriver->Send (aMethStr + "error: shape section is not found", Message_Fail);
myReaderStatus = PCDM_RS_ReaderException;
//purpose :
//=======================================================================
-void BinLDrivers_DocumentSection::ReadTOC
- (BinLDrivers_DocumentSection& theSection,
+Standard_Boolean BinLDrivers_DocumentSection::ReadTOC (
+ BinLDrivers_DocumentSection& theSection,
Standard_IStream& theStream,
const TDocStd_FormatVersion theDocFormatVersion)
{
- char aBuf[512];
+ static const int THE_BUF_SIZE = 512;
+ char aBuf[THE_BUF_SIZE];
Standard_Integer aNameBufferSize;
theStream.read ((char *)&aNameBufferSize, sizeof(Standard_Integer));
+ if (theStream.eof() || aNameBufferSize > THE_BUF_SIZE)
+ return Standard_False;
#ifdef DO_INVERSE
aNameBufferSize = InverseSize(aNameBufferSize);
#endif
theSection.myValue[1] = aValue[1];
theSection.myIsPostRead = (aValue[2] != 0);
}
+ return Standard_True;
}
const TDocStd_FormatVersion theDocFormatVersion);
//! Fill a DocumentSection instance from the data that are read
- //! from TOC.
- Standard_EXPORT static void ReadTOC (BinLDrivers_DocumentSection& theSection, Standard_IStream& theIS,
- const TDocStd_FormatVersion theDocFormatVersion);
+ //! from TOC. Returns false in case of the stream reading problem.
+ Standard_EXPORT static Standard_Boolean ReadTOC (BinLDrivers_DocumentSection& theSection,
+ Standard_IStream& theIS,
+ const TDocStd_FormatVersion theDocFormatVersion);
# check memory usage (with tolerance equal to half page size)
lappend listmem [meminfo h]
- checktrend $listmem 0 1 "Memory leak detected"
+ checktrend $listmem 50 50 "Memory leak detected"
}
SaveAs D $docname
Close D
+# make the first open/close iteration before checking memory because some filled structures
+# are cleared on start of the next open (like mySections in DocumentRetrievalDriver)
+Open $docname D
+Close D
+
puts "Executing Load / Close in cycle to see if allocated heap memory grows"
set listmem {}
for {set i 1} {$i < 10} {incr i} {