mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2024-12-25 08:50:35 +05:00
Fix memory corruption introduced into ef9db08c81
This commit is contained in:
parent
ef9db08c81
commit
e34095b65b
@ -369,24 +369,19 @@ Driver_Mesh::Status DriverMED_W_Field::Perform()
|
||||
*/
|
||||
Driver_Mesh::Status DriverMED_W_Field_Mem::Perform()
|
||||
{
|
||||
void *ptr(nullptr);
|
||||
std::size_t sz(0);
|
||||
Driver_Mesh::Status status = Driver_Mesh::DRS_OK;
|
||||
bool isClosed(false);
|
||||
MED::TMemFile *tfileInst = nullptr;
|
||||
char *initPtr(_data->getPointer());
|
||||
mcIdType initSz(_data->getNumberOfTuples());
|
||||
void *ptr(_data->getPointer());
|
||||
std::size_t sz(_data->getNumberOfTuples());
|
||||
_data->accessToMemArray().setSpecificDeallocator(nullptr);
|
||||
_data->useArray(nullptr,false,MEDCoupling::DeallocType::C_DEALLOC,0,1);
|
||||
{// let braces to flush (call of MED::PWrapper myMed destructor)
|
||||
tfileInst = new MED::TMemFile(initPtr,initSz,&isClosed);
|
||||
MED::TMemFile *tfileInst = new MED::TMemFile(&ptr,&sz,&isClosed);
|
||||
MED::PWrapper myMed = MED::CrWrapperW(myFile, -1, tfileInst);
|
||||
status = this->PerformInternal(myMed);
|
||||
}
|
||||
if(tfileInst)
|
||||
{
|
||||
ptr = tfileInst->getData(); sz = tfileInst->getSize();
|
||||
}
|
||||
if(!isClosed)
|
||||
EXCEPTION(std::runtime_error, "TFTMemFile destructor : on destruction file has not been closed properly -> chunk of memory data may be invalid !");
|
||||
_data = MEDCoupling::DataArrayByte::New();
|
||||
_data->useArray(reinterpret_cast<char *>(ptr),true,MEDCoupling::DeallocType::C_DEALLOC,sz,1);
|
||||
return status;
|
||||
|
@ -356,16 +356,13 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh_Mem::Perform()
|
||||
std::size_t sz(0);
|
||||
Driver_Mesh::Status status = Driver_Mesh::DRS_OK;
|
||||
bool isClosed(false);
|
||||
TMemFile *tfileInst = nullptr;
|
||||
{// let braces to flush (call of MED::PWrapper myMed destructor)
|
||||
tfileInst = new TMemFile(&isClosed);
|
||||
TMemFile *tfileInst = new TMemFile(&ptr,&sz,&isClosed);// this new will be destroyed by destructor of myMed
|
||||
MED::PWrapper myMed = CrWrapperW(myFile, -1, tfileInst);
|
||||
status = this->PerformInternal<MED::PWrapper>(myMed);
|
||||
}
|
||||
if(tfileInst)
|
||||
{
|
||||
ptr = tfileInst->getData(); sz = tfileInst->getSize();
|
||||
}
|
||||
if(!isClosed)
|
||||
EXCEPTION(std::runtime_error, "TFTMemFile destructor : on destruction file has not been closed properly -> chunk of memory data may be invalid !");
|
||||
_data = MEDCoupling::DataArrayByte::New();
|
||||
_data->useArray(reinterpret_cast<char *>(ptr),true,MEDCoupling::DeallocType::C_DEALLOC,sz,1);
|
||||
if(!isClosed)
|
||||
|
@ -73,12 +73,14 @@ namespace MED
|
||||
class MEDWRAPPER_EXPORT TMemFile : public MEDIDTHoder
|
||||
{
|
||||
public:
|
||||
TMemFile(bool* isClosedStatus = nullptr):MEDIDTHoder(isClosedStatus) { memfile.app_image_ptr=nullptr; memfile.app_image_size=0; }
|
||||
TMemFile(void *data, std::size_t sz, bool* isClosedStatus):MEDIDTHoder(isClosedStatus) { memfile.app_image_ptr=data; memfile.app_image_size=sz; }
|
||||
TMemFile(void **data, std::size_t *sz, bool* isClosedStatus):MEDIDTHoder(isClosedStatus),_data(data),_sz(sz) { memfile.app_image_ptr=*data; memfile.app_image_size=*sz; }
|
||||
~TMemFile() { UnRefFid(); if(myIsClosed) { *_data = memfile.app_image_ptr; *_sz = memfile.app_image_size; } }
|
||||
void Open(EModeAcces theMode, TErr* theErr = nullptr) override;
|
||||
void *getData() const { return memfile.app_image_ptr; }
|
||||
std::size_t getSize() const { return memfile.app_image_size; }
|
||||
private:
|
||||
void **_data = nullptr;
|
||||
std::size_t * _sz = nullptr;
|
||||
med_memfile memfile = MED_MEMFILE_INIT;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user