1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +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:
abv
2020-05-04 22:25:03 +03:00
committed by bugmaster
parent dcc4e908c2
commit 39c8dc708f
54 changed files with 664 additions and 2475 deletions

View File

@@ -30,6 +30,57 @@
#include <StdStorage_TypeData.hxx>
#include <ShapePersistent_TopoDS.hxx>
//==========================================================
// ErrorMessage
//==========================================================
static void DDocStd_StorageErrorMessage (Draw_Interpretor& theDI, const Storage_Error theStatus)
{
switch (theStatus) {
case Storage_VSOk:
break;
case Storage_VSOpenError:
theDI << "Storage error: failed to open the stream";
break;
case Storage_VSModeError:
theDI << "Storage error: the stream is opened with a wrong mode for operation ";
break;
case Storage_VSCloseError:
theDI << "Storage error: failed to closing the stream";
break;
case Storage_VSAlreadyOpen:
theDI << "Storage error: stream is already opened";
break;
case Storage_VSNotOpen:
theDI << "Storage error: stream not opened";
break;
case Storage_VSSectionNotFound:
theDI << "Storage error: the section is not found";
break;
case Storage_VSWriteError:
theDI << "Storage error: error during writing";
break;
case Storage_VSFormatError:
theDI << "Storage error: wrong format error occured while reading";
break;
case Storage_VSUnknownType:
theDI << "Storage error: try to read an unknown type";
break;
case Storage_VSTypeMismatch:
theDI << "Storage error: try to read a wrong primitive type (read a char while expecting a real)";
break;
case Storage_VSInternalError:
theDI << "Storage error: internal error";
break;
case Storage_VSExtCharParityError:
theDI << "Storage error: parity error";
break;
default:
theDI << "Storage error: unknown error code";
break;
}
}
//=======================================================================
//function : DDocStd_ShapeSchema_Write
//=======================================================================
@@ -51,7 +102,7 @@ static Standard_Integer DDocStd_fsdwrite(Draw_Interpretor& theDI,
return 1;
}
NCollection_Handle<Storage_BaseDriver> aFileDriver(new FSD_File);
Handle(Storage_BaseDriver) aFileDriver(new FSD_File);
Standard_Boolean hasStorageDriver = Standard_False;
Standard_Integer iArgN = theArgNb - 1;
@@ -76,8 +127,9 @@ static Standard_Integer DDocStd_fsdwrite(Draw_Interpretor& theDI,
Storage_Error aStatus = aFileDriver->Open(theArgs[iArgN], Storage_VSWrite);
if (aStatus != Storage_VSOk) {
theDI << "Error : couldn't open file '" << "' for writing (" << aStatus << ")\n";
return 1;
theDI << "Error: cannot open file '" << "' for writing (" << aStatus << ")\n";
DDocStd_StorageErrorMessage (theDI, aStatus);
return 0;
}
TopTools_SequenceOfShape aShapes;
@@ -129,15 +181,9 @@ static Standard_Integer DDocStd_fsdwrite(Draw_Interpretor& theDI,
aData->RootData()->AddRoot(aRoot);
}
Storage_Error anError = StdStorage::Write(*aFileDriver, aData);
Storage_Error anError = StdStorage::Write(aFileDriver, aData);
aFileDriver->Close();
if (anError != Storage_VSOk)
{
theDI << "Error : " << anError << "\n";
return 1;
}
DDocStd_StorageErrorMessage(theDI, anError);
return 0;
}
@@ -170,8 +216,8 @@ static Standard_Integer DDocStd_fsdread(Draw_Interpretor& theDI,
Storage_Error anError = StdStorage::Read(TCollection_AsciiString(theArgs[1]), aData);
if (anError != Storage_VSOk)
{
theDI << "Error : " << anError << "\n";
return 1;
DDocStd_StorageErrorMessage(theDI, anError);
return 0;
}
TopTools_SequenceOfShape aShapes;