mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-29 14:00:49 +03:00
0031546: Application Framework - Memory leak (100 bytes) on Load / Close OCAF document
Class Standard_BaseDriver is inherited from Standard_Transient, its descendants are updated accordingly. Handle is used to manipulate objects of this class and its descendants (instead of references or raw pointers) to ensure automatic destruction. Added test bugs caf bug31546 Related: - Standard_OVERRIDE is added in declarations of virtual methods in descendants of Storage_BaseDriver - Methods operator << and operator >> are removed in descendants of Storage_BaseDriver (they repeat the same methods inherited from the base class) - Typedef PCDM_BaseDriverPointer is marked as deprecated - Unused class DDI_Ostream is removed - Private field Standard_Transient::count is renamed to myRefCount_ to avoid compiler warnings if the same name is used within the scope of a descendant class - Output of meaningful error messages is restored in DRAW commands fsdread and fsdwrite
This commit is contained in:
@@ -37,7 +37,8 @@
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileName, PCDM_BaseDriverPointer& aBaseDriver) {
|
||||
PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileName, Handle(Storage_BaseDriver)& aBaseDriver)
|
||||
{
|
||||
if(FSD_CmpFile::IsGoodFileType(aFileName) == Storage_VSOk) {
|
||||
aBaseDriver=new FSD_CmpFile;
|
||||
return PCDM_TOFD_CmpFile;
|
||||
@@ -61,7 +62,7 @@ PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileN
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
PCDM_TypeOfFileDriver PCDM::FileDriverType (Standard_IStream& theIStream, PCDM_BaseDriverPointer& theBaseDriver)
|
||||
PCDM_TypeOfFileDriver PCDM::FileDriverType (Standard_IStream& theIStream, Handle(Storage_BaseDriver)& theBaseDriver)
|
||||
{
|
||||
TCollection_AsciiString aReadMagicNumber;
|
||||
|
||||
|
@@ -17,26 +17,21 @@
|
||||
#ifndef _PCDM_HeaderFile
|
||||
#define _PCDM_HeaderFile
|
||||
|
||||
#include <Standard.hxx>
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
#include <Standard_Handle.hxx>
|
||||
|
||||
#include <Standard_IStream.hxx>
|
||||
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <Storage_BaseDriver.hxx>
|
||||
#include <PCDM_TypeOfFileDriver.hxx>
|
||||
#include <PCDM_BaseDriverPointer.hxx>
|
||||
|
||||
class CDM_Document;
|
||||
class PCDM_StorageDriver;
|
||||
class TCollection_AsciiString;
|
||||
|
||||
|
||||
class PCDM
|
||||
{
|
||||
public:
|
||||
Standard_EXPORT static PCDM_TypeOfFileDriver FileDriverType (const TCollection_AsciiString& aFileName, PCDM_BaseDriverPointer& aBaseDriver);
|
||||
Standard_EXPORT static PCDM_TypeOfFileDriver FileDriverType (const TCollection_AsciiString& aFileName,
|
||||
Handle(Storage_BaseDriver)& aBaseDriver);
|
||||
|
||||
Standard_EXPORT static PCDM_TypeOfFileDriver FileDriverType (Standard_IStream& theIStream, PCDM_BaseDriverPointer& theBaseDriver);
|
||||
Standard_EXPORT static PCDM_TypeOfFileDriver FileDriverType (Standard_IStream& theIStream,
|
||||
Handle(Storage_BaseDriver)& theBaseDriver);
|
||||
|
||||
DEFINE_STANDARD_ALLOC
|
||||
};
|
||||
|
@@ -18,6 +18,8 @@
|
||||
#define _PCDM_BaseDriverPointer_HeaderFile
|
||||
|
||||
class Storage_BaseDriver;
|
||||
typedef Storage_BaseDriver* PCDM_BaseDriverPointer;
|
||||
|
||||
Standard_DEPRECATED("Typedef PCDM_BaseDriverPointer is kept for compatibility only, instead consider using Handle(Storage_BaseDriver) explicitly")
|
||||
typedef Handle(Storage_BaseDriver) PCDM_BaseDriverPointer;
|
||||
|
||||
#endif // _PCDM_BaseDriverPointer_HeaderFile
|
||||
|
@@ -45,7 +45,7 @@ static TCollection_ExtendedString TryXmlDriverType (Standard_IStream& theIStream
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void PCDM_ReadWriter::Open (Storage_BaseDriver& aDriver,
|
||||
void PCDM_ReadWriter::Open (const Handle(Storage_BaseDriver)& aDriver,
|
||||
const TCollection_ExtendedString& aFileName,
|
||||
const Storage_OpenMode aMode)
|
||||
{
|
||||
@@ -113,7 +113,7 @@ TCollection_ExtendedString PCDM_ReadWriter::FileFormat
|
||||
{
|
||||
TCollection_ExtendedString theFormat;
|
||||
|
||||
PCDM_BaseDriverPointer theFileDriver;
|
||||
Handle(Storage_BaseDriver) theFileDriver;
|
||||
|
||||
// conversion to UTF-8 is done inside
|
||||
TCollection_AsciiString theFileName (aFileName);
|
||||
@@ -126,10 +126,10 @@ TCollection_ExtendedString PCDM_ReadWriter::FileFormat
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
|
||||
Open(*theFileDriver,aFileName,Storage_VSRead);
|
||||
Open(theFileDriver,aFileName,Storage_VSRead);
|
||||
theFileIsOpen=Standard_True;
|
||||
Storage_HeaderData hd;
|
||||
hd.Read (*theFileDriver);
|
||||
hd.Read (theFileDriver);
|
||||
const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
|
||||
Standard_Boolean found=Standard_False;
|
||||
for (Standard_Integer i =1; !found && i<= refUserInfo.Length() ; i++) {
|
||||
@@ -142,16 +142,16 @@ TCollection_ExtendedString PCDM_ReadWriter::FileFormat
|
||||
if (!found)
|
||||
{
|
||||
Storage_TypeData td;
|
||||
td.Read (*theFileDriver);
|
||||
td.Read (theFileDriver);
|
||||
theFormat = td.Types()->Value(1);
|
||||
}
|
||||
}
|
||||
catch (Standard_Failure const&) {}
|
||||
|
||||
|
||||
if(theFileIsOpen)theFileDriver->Close();
|
||||
|
||||
delete theFileDriver;
|
||||
if(theFileIsOpen)
|
||||
{
|
||||
theFileDriver->Close();
|
||||
}
|
||||
|
||||
return theFormat;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ TCollection_ExtendedString PCDM_ReadWriter::FileFormat (Standard_IStream& theISt
|
||||
{
|
||||
TCollection_ExtendedString aFormat;
|
||||
|
||||
Storage_BaseDriver* aFileDriver = 0L;
|
||||
Handle(Storage_BaseDriver) aFileDriver;
|
||||
if (PCDM::FileDriverType (theIStream, aFileDriver) == PCDM_TOFD_XmlFile)
|
||||
{
|
||||
return ::TryXmlDriverType (theIStream);
|
||||
|
@@ -62,7 +62,9 @@ public:
|
||||
|
||||
Standard_EXPORT virtual Standard_Integer ReadDocumentVersion (const TCollection_ExtendedString& aFileName, const Handle(Message_Messenger)& theMsgDriver) const = 0;
|
||||
|
||||
Standard_EXPORT static void Open (Storage_BaseDriver& aDriver, const TCollection_ExtendedString& aFileName, const Storage_OpenMode anOpenMode);
|
||||
Standard_EXPORT static void Open (const Handle(Storage_BaseDriver)& aDriver,
|
||||
const TCollection_ExtendedString& aFileName,
|
||||
const Storage_OpenMode anOpenMode);
|
||||
|
||||
//! returns the convenient Reader for a File.
|
||||
Standard_EXPORT static Handle(PCDM_ReadWriter) Reader (const TCollection_ExtendedString& aFileName);
|
||||
|
@@ -230,7 +230,7 @@ Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_Exten
|
||||
theReferencesCounter=0;
|
||||
static Standard_Integer i ;
|
||||
|
||||
PCDM_BaseDriverPointer theFileDriver;
|
||||
Handle(Storage_BaseDriver) theFileDriver;
|
||||
TCollection_AsciiString aFileNameU(aFileName);
|
||||
if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
|
||||
return theReferencesCounter;
|
||||
@@ -240,12 +240,12 @@ Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_Exten
|
||||
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
PCDM_ReadWriter::Open(*theFileDriver,aFileName,Storage_VSRead);
|
||||
PCDM_ReadWriter::Open(theFileDriver,aFileName,Storage_VSRead);
|
||||
theFileIsOpen=Standard_True;
|
||||
|
||||
Handle(Storage_Schema) s = new Storage_Schema;
|
||||
Storage_HeaderData hd;
|
||||
hd.Read (*theFileDriver);
|
||||
hd.Read (theFileDriver);
|
||||
const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
|
||||
|
||||
for ( i =1; i<= refUserInfo.Length() ; i++) {
|
||||
@@ -264,9 +264,11 @@ Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_Exten
|
||||
}
|
||||
catch (Standard_Failure const&) {}
|
||||
|
||||
if(theFileIsOpen) theFileDriver->Close();
|
||||
if(theFileIsOpen)
|
||||
{
|
||||
theFileDriver->Close();
|
||||
}
|
||||
|
||||
delete theFileDriver;
|
||||
return theReferencesCounter;
|
||||
}
|
||||
|
||||
@@ -338,18 +340,18 @@ void PCDM_ReadWriter_1::ReadUserInfo(const TCollection_ExtendedString& aFileName
|
||||
const TCollection_AsciiString& Start,
|
||||
const TCollection_AsciiString& End,
|
||||
TColStd_SequenceOfExtendedString& theUserInfo,
|
||||
const Handle(Message_Messenger)&) {
|
||||
|
||||
const Handle(Message_Messenger)&)
|
||||
{
|
||||
static Standard_Integer i ;
|
||||
PCDM_BaseDriverPointer theFileDriver;
|
||||
Handle(Storage_BaseDriver) theFileDriver;
|
||||
TCollection_AsciiString aFileNameU(aFileName);
|
||||
if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
|
||||
return;
|
||||
|
||||
PCDM_ReadWriter::Open(*theFileDriver,aFileName,Storage_VSRead);
|
||||
PCDM_ReadWriter::Open(theFileDriver,aFileName,Storage_VSRead);
|
||||
Handle(Storage_Schema) s = new Storage_Schema;
|
||||
Storage_HeaderData hd;
|
||||
hd.Read (*theFileDriver);
|
||||
hd.Read (theFileDriver);
|
||||
const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
|
||||
|
||||
Standard_Integer debut=0,fin=0;
|
||||
@@ -366,7 +368,6 @@ void PCDM_ReadWriter_1::ReadUserInfo(const TCollection_ExtendedString& aFileName
|
||||
}
|
||||
}
|
||||
theFileDriver->Close();
|
||||
delete theFileDriver;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@@ -379,7 +380,7 @@ Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion(const TCollection_Extend
|
||||
static Standard_Integer theVersion ;
|
||||
theVersion=-1;
|
||||
|
||||
PCDM_BaseDriverPointer theFileDriver;
|
||||
Handle(Storage_BaseDriver) theFileDriver;
|
||||
TCollection_AsciiString aFileNameU(aFileName);
|
||||
if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
|
||||
return theVersion;
|
||||
@@ -389,11 +390,11 @@ Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion(const TCollection_Extend
|
||||
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
PCDM_ReadWriter::Open(*theFileDriver,aFileName,Storage_VSRead);
|
||||
PCDM_ReadWriter::Open(theFileDriver,aFileName,Storage_VSRead);
|
||||
theFileIsOpen=Standard_True;
|
||||
Handle(Storage_Schema) s = new Storage_Schema;
|
||||
Storage_HeaderData hd;
|
||||
hd.Read (*theFileDriver);
|
||||
hd.Read (theFileDriver);
|
||||
const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
|
||||
|
||||
static Standard_Integer i ;
|
||||
@@ -414,7 +415,10 @@ Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion(const TCollection_Extend
|
||||
|
||||
catch (Standard_Failure const&) {}
|
||||
|
||||
if(theFileIsOpen) theFileDriver->Close();
|
||||
delete theFileDriver;
|
||||
if(theFileIsOpen)
|
||||
{
|
||||
theFileDriver->Close();
|
||||
}
|
||||
|
||||
return theVersion;
|
||||
}
|
||||
|
@@ -91,10 +91,10 @@ void PCDM_StorageDriver::Write(const Handle(CDM_Document)& aDocument, const TCol
|
||||
theData->AddToComments(aComments(i));
|
||||
}
|
||||
|
||||
FSD_CmpFile theFile;
|
||||
Handle(FSD_CmpFile) theFile = new FSD_CmpFile;
|
||||
PCDM_ReadWriter::Open(theFile,aFileName,Storage_VSWrite);
|
||||
theSchema->Write(theFile,theData);
|
||||
theFile.Close();
|
||||
theFile->Close();
|
||||
|
||||
if ( theData->ErrorStatus() != Storage_VSOk )
|
||||
throw PCDM_DriverError(theData->ErrorStatusExtension().ToCString());
|
||||
|
Reference in New Issue
Block a user