Commit 5d89e8dc authored by Kenneth Leiter's avatar Kenneth Leiter
Browse files

BUG: Fixes a large number of memory leaks detected with TotalView.

parent 082216d5
......@@ -954,6 +954,7 @@ if( this->GetNumberType() == XDMF_INT8_TYPE || this->GetNumberType() == XDMF_INT
while( NumberOfValues-- ) {
StringOutput << (long)IntValues[i++] << " ";
}
delete [] IntValues;
}
else {
FloatValues = new XdmfFloat64[ NumberOfValues + 10];
......@@ -962,6 +963,7 @@ else {
while( NumberOfValues-- ) {
StringOutput << (double)FloatValues[i++] << " ";
}
delete [] FloatValues;
}
StringOutput << ends;
......
......@@ -97,7 +97,7 @@ XdmfAttribute::Build(){
di->SetArray(this->Values);
if(this->Values->GetNumberOfElements() > this->LightDataLimit) di->SetFormat(XDMF_FORMAT_HDF);
di->Build();
delete di;
}
// PATCH September 09, Ian Curington, HR Wallingford Ltd.
if(this->Units)
......@@ -238,6 +238,7 @@ if( Attribute ){
} else {
this->AttributeType = XDMF_ATTRIBUTE_TYPE_SCALAR;
}
delete [] Attribute;
// PATCH September 09, Ian Curinton HR Wallingford Ltd.
Attribute = this->Get( "Units" );
......@@ -248,6 +249,7 @@ if( Attribute ){
this->Units = NULL;
}
// end patch
delete [] Attribute;
Attribute = this->Get( "Active" );
this->Active = 0;
......@@ -256,6 +258,7 @@ if ( Attribute ){
this->Active = 1;
}
}
delete [] Attribute;
Attribute = this->Get( "Center" );
if( Attribute ){
......@@ -263,6 +266,8 @@ if( Attribute ){
} else {
this->AttributeCenter = XDMF_ATTRIBUTE_CENTER_NODE;
}
delete [] Attribute;
Attribute = this->Get( "Dimensions" );
if( Attribute ){
this->ShapeDesc->SetShapeFromString( Attribute );
......@@ -275,12 +280,14 @@ if( Attribute ){
Attribute = this->DOM->Get( ValuesNode, "Dimensions" );
if(!Attribute){
XdmfErrorMessage("Dimensions of Attribute not set in XML or DataItem");
delete [] Attribute;
return(XDMF_FAIL);
}else{
this->ShapeDesc->SetShapeFromString( Attribute );
}
}
if(!this->Name) this->SetName(GetUnique("Attribute_"));
delete [] Attribute;
return( XDMF_SUCCESS );
}
......
......@@ -58,7 +58,7 @@ XdmfDOM::XdmfDOM(){
this->Output = &cout;
this->Input = &cin;
this->Doc = NULL;
this->DTD = 1;
this->DTD = 1;
this->OutputFileName = 0;
XDMF_STRING_DUPLICATE(this->OutputFileName, "stdout");
this->SetFileName("stdin");
......@@ -76,6 +76,7 @@ XdmfDOM::~XdmfDOM(){
if( ( this->Output != &cout ) && ( this->Output != &cerr ) ) {
ofstream *OldOutput = ( ofstream *)this->Output;
OldOutput->close();
delete OldOutput;
}
if( this->Input != &cin ) {
XdmfDebug("Deleting Input");
......
......@@ -52,8 +52,8 @@ XdmfDataItem::XdmfDataItem() {
this->HeavyDataSetName = NULL;
this->ItemType = XDMF_ITEM_UNIFORM;
this->Function = NULL;
this->ColumnMajor = 0;
this->TransposeInMemory = 1;
this->ColumnMajor = 0;
this->TransposeInMemory = 1;
}
XdmfDataItem::~XdmfDataItem() {
......@@ -65,6 +65,7 @@ XdmfDataItem::~XdmfDataItem() {
}
if(this->DataDesc && this->DataDescIsMine) delete this->DataDesc;
if(this->Values) delete this->Values;
delete [] this->HeavyDataSetName;
}
XdmfInt32
......@@ -155,6 +156,7 @@ XdmfInt32 XdmfDataItem::UpdateInformationFunction(){
case XDMF_ITEM_COORDINATES :
break;
}
delete [] Value;
return(XDMF_SUCCESS);
}
......@@ -172,6 +174,7 @@ XdmfInt32 XdmfDataItem::UpdateInformationUniform(){
Value = this->Get("Precision");
if(Value) Precision = atoi(Value);
delete [] Value;
Value = this->Get("NumberType");
// Try DataType
if(!Value) Value = this->Get("DataType");
......@@ -201,6 +204,7 @@ XdmfInt32 XdmfDataItem::UpdateInformationUniform(){
this->DataDesc->SetNumberType(XDMF_FLOAT32_TYPE);
}
}
delete [] Value;
Value = this->Get("Format");
// Currently XML or HDF5
if(XDMF_WORD_CMP(Value, "HDF")){
......@@ -217,8 +221,10 @@ XdmfInt32 XdmfDataItem::UpdateInformationUniform(){
this->SetFormat(XDMF_FORMAT_BINARY);
}else if(Value){
XdmfErrorMessage("Unsupported DataItem Format :" << Value);
delete [] Value;
return(XDMF_FAIL);
}
delete [] Value;
return(XDMF_SUCCESS);
}
......@@ -235,6 +241,7 @@ XdmfInt32 XdmfDataItem::UpdateInformation(){
else
{
XdmfErrorMessage("invalid major");
delete [] Value;
return(XDMF_FAIL);
}
}
......@@ -248,6 +255,7 @@ XdmfInt32 XdmfDataItem::UpdateInformation(){
// XdmfDebug("r = " << this->ReferenceElement << " e = " << this->Element);
// XdmfDebug(this->DOM->Serialize(this->ReferenceElement));
// Dtetermine type : Uniform, Collection, or Tree
delete [] Value;
Value = this->Get("ItemType");
if(!Value){
// Try Old "Type=XX" Style from Xdmf Version 1.0
......@@ -292,6 +300,7 @@ XdmfInt32 XdmfDataItem::UpdateInformation(){
XdmfDebug("Reference DataItem Copied Info from another ReferenceObject");
return(XDMF_SUCCESS);
}
delete [] Value;
Value = this->Get("Dimensions");
if(!Value) {
XdmfErrorMessage("Dimensions are not set in XML Element");
......@@ -300,6 +309,7 @@ XdmfInt32 XdmfDataItem::UpdateInformation(){
}
if(!this->DataDesc) this->DataDesc = new XdmfDataDesc();
this->DataDesc->SetShapeFromString(Value);
delete [] Value;
switch(this->ItemType){
case XDMF_ITEM_UNIFORM :
return(this->UpdateInformationUniform());
......
......@@ -45,7 +45,7 @@ class XDMF_EXPORT XdmfElementData : public XdmfObject {
XdmfElement *ReferenceElement;
XdmfElement *CurrentXdmfElement;
};
XdmfElementData::XdmfElementData(){
this->ReferenceElement = NULL;
this->CurrentXdmfElement = NULL;
......@@ -67,6 +67,7 @@ XdmfElement::XdmfElement() {
this->DataXml = 0;
this->InsertedDataXml = 0;
this->DeleteOnGridDelete = 0;
this->PrivateData = NULL;
}
XdmfElement::~XdmfElement() {
......@@ -83,31 +84,33 @@ XdmfElement::~XdmfElement() {
}
}
}
if(this->PrivateData) delete this->PrivateData;
this->Element = NULL;
if(this->ElementName) delete [] this->ElementName;
if(this->DataXml) delete [] this->DataXml;
}
void XdmfElement::SetReferenceObject(XdmfXmlNode anElement, void *p){
XdmfElementData *PrivateData;
XdmfElementData *ElementPrivateData;
if(!anElement){
XdmfErrorMessage("Element is NULL");
return;
}
if(XDMF_XML_PRIVATE_DATA(anElement)){
PrivateData = (XdmfElementData *)XDMF_XML_PRIVATE_DATA(anElement);
ElementPrivateData = (XdmfElementData *)XDMF_XML_PRIVATE_DATA(anElement);
}else{
PrivateData = new XdmfElementData;
XDMF_XML_PRIVATE_DATA(anElement) = (void *)PrivateData;
ElementPrivateData = new XdmfElementData;
XDMF_XML_PRIVATE_DATA(anElement) = (void *)ElementPrivateData;
this->PrivateData = ElementPrivateData;
}
// XdmfDebug("Old Ref = " << PrivateData->GetReferenceElement());
// XdmfDebug("Old Ref = " << ElementPrivateData->GetReferenceElement());
// XdmfDebug("New Ref = " << p);
PrivateData->SetReferenceElement((XdmfElement *)p);
ElementPrivateData->SetReferenceElement((XdmfElement *)p);
}
void *
XdmfElement::GetReferenceObject(XdmfXmlNode anElement){
XdmfElementData *PrivateData;
XdmfElementData *ElementPrivateData;
if(!anElement){
XdmfErrorMessage("NULL Reference Element");
return(NULL);
......@@ -116,45 +119,46 @@ XdmfElement::GetReferenceObject(XdmfXmlNode anElement){
XdmfDebug("XML Node contains no initialized object");
return(NULL);
}
PrivateData = (XdmfElementData *)XDMF_XML_PRIVATE_DATA(anElement);
if(PrivateData->GetReferenceElement() == XDMF_EMPTY_REFERENCE){
ElementPrivateData = (XdmfElementData *)XDMF_XML_PRIVATE_DATA(anElement);
if(ElementPrivateData->GetReferenceElement() == XDMF_EMPTY_REFERENCE){
XdmfDebug("XML Node contains no initialized object");
return(NULL);
}
return(PrivateData->GetReferenceElement());
return(ElementPrivateData->GetReferenceElement());
}
void XdmfElement::SetCurrentXdmfElement(XdmfXmlNode anElement, void *p){
XdmfElementData *PrivateData;
XdmfElementData *ElementPrivateData;
if(!anElement){
XdmfErrorMessage("Element is NULL");
return;
}
if(XDMF_XML_PRIVATE_DATA(anElement)){
PrivateData = (XdmfElementData *)XDMF_XML_PRIVATE_DATA(anElement);
ElementPrivateData = (XdmfElementData *)XDMF_XML_PRIVATE_DATA(anElement);
}else{
PrivateData = new XdmfElementData;
XDMF_XML_PRIVATE_DATA(anElement) = (void *)PrivateData;
ElementPrivateData = new XdmfElementData;
XDMF_XML_PRIVATE_DATA(anElement) = (void *)ElementPrivateData;
this->PrivateData = ElementPrivateData;
}
PrivateData->SetCurrentXdmfElement((XdmfElement *)p);
ElementPrivateData->SetCurrentXdmfElement((XdmfElement *)p);
}
void *
XdmfElement::GetCurrentXdmfElement(XdmfXmlNode anElement){
XdmfElementData *PrivateData;
XdmfElementData *ElementPrivateData;
if(!anElement){
XdmfErrorMessage("NULL Reference Element");
return(NULL);
}
PrivateData = (XdmfElementData *)XDMF_XML_PRIVATE_DATA(anElement);
if(!PrivateData){
ElementPrivateData = (XdmfElementData *)XDMF_XML_PRIVATE_DATA(anElement);
if(!ElementPrivateData){
return(NULL);
}
if(PrivateData->GetCurrentXdmfElement() == XDMF_EMPTY_REFERENCE){
if(ElementPrivateData->GetCurrentXdmfElement() == XDMF_EMPTY_REFERENCE){
XdmfDebug("XML Node contains no initialized object");
return(NULL);
}
return(PrivateData->GetCurrentXdmfElement());
return(ElementPrivateData->GetCurrentXdmfElement());
}
XdmfInt32 XdmfElement::SetElement(XdmfXmlNode anElement, XdmfInt32 AssociateElement){
......@@ -162,7 +166,7 @@ XdmfInt32 XdmfElement::SetElement(XdmfXmlNode anElement, XdmfInt32 AssociateElem
XdmfErrorMessage("Element is NULL");
return(XDMF_FAIL);
}
// Clear the ReferenceObject underlying node. This will also create PrivateData if necessary
// Clear the ReferenceObject underlying node. This will also create ElementPrivateData if necessary
XdmfDebug("Clearing ReferenceObject of XML node");
this->SetReferenceObject(anElement, XDMF_EMPTY_REFERENCE);
if(AssociateElement) this->SetCurrentXdmfElement(anElement, this);
......@@ -247,6 +251,7 @@ XdmfInt32 XdmfElement::UpdateInformation(){
ref = this->CheckForReference(this->Element);
if(ref == (XdmfXmlNode)XDMF_ERROR_REFERENCE){
XdmfErrorMessage("Error Checking Reference");
delete [] Value;
return(XDMF_FAIL);
}
if(ref){
......@@ -269,6 +274,7 @@ XdmfInt32 XdmfElement::UpdateInformation(){
// Copy out appropriate information and return
XdmfDebug("Copying Information from Reference Object");
this->Element = e->Element;
delete [] Value;
return(this->Copy(e));
}
// No ReferenceObject Set. Is this a Reference as well?
......@@ -279,6 +285,7 @@ XdmfInt32 XdmfElement::UpdateInformation(){
// Not a Reference. Is it the right Type ?
if(STRCMP((const char *)ref->name, (const char *)this->ReferenceElement->name) != 0){
XdmfErrorMessage("Reference node " << Value << " is a " << ref->name << " not " << ReferenceElement->name);
delete [] Value;
return(XDMF_FAIL);
}
// If this is a derived Class, UpdateInformation will act on this target.
......@@ -293,6 +300,7 @@ XdmfInt32 XdmfElement::UpdateInformation(){
XdmfDebug("Setting Reference Object");
this->SetReferenceObject(this->Element, this);
}
delete [] Value;
this->State = XDMF_ELEMENT_STATE_LIGHT_PARSED;
return(XDMF_SUCCESS);
}
......
......@@ -208,5 +208,6 @@ protected:
XdmfDsmBuffer *DsmBuffer;
XdmfXmlNode RootWhenParsed;
XdmfInt32 DeleteOnGridDelete;
void *PrivateData;
};
#endif // __XdmfElement_h
......@@ -185,6 +185,7 @@ XdmfGeometry::Build(){
di->SetArray(this->Points);
if(this->Points->GetNumberOfElements() > this->LightDataLimit) di->SetFormat(XDMF_FORMAT_HDF);
di->Build();
delete di;
}else{
XdmfErrorMessage("XdmfGeometry->Points must be set for Geometry Type " << this->GetGeometryTypeAsString());
return(XDMF_FAIL);
......@@ -360,7 +361,7 @@ XdmfGeometry::UpdateInformation() {
this->Units = NULL;
}
// end patch
delete [] Attribute;
Attribute = this->Get( "GeometryType" );
if(!Attribute){
Attribute = this->Get( "Type" );
......@@ -368,12 +369,14 @@ XdmfGeometry::UpdateInformation() {
if( Attribute ){
if(this->SetGeometryTypeFromString( Attribute ) != XDMF_SUCCESS){
XdmfErrorMessage("No such Geometry Type : " << Attribute);
delete [] Attribute;
return(XDMF_FAIL);
}
} else {
this->GeometryType = XDMF_GEOMETRY_XYZ;
}
if(!this->Name) this->SetName(GetUnique("Geometry_"));
delete[] Attribute;
return( XDMF_SUCCESS );
}
......
......@@ -401,11 +401,13 @@ if( XDMF_WORD_CMP(attribute, "Collection") ){
}else{
if(attribute){
XdmfErrorMessage("Unknown Grid Type " << attribute);
delete [] attribute;
return(XDMF_FAIL);
}
// If Type is NULL use default
this->GridType = XDMF_GRID_UNIFORM;
}
delete [] attribute;
if( this->GridType & XDMF_GRID_MASK){
// SubSet Tree or Collection
XdmfInt32 i, nchild;
......@@ -468,6 +470,7 @@ if( this->GridType & XDMF_GRID_MASK){
select = this->DOM->FindElement("DataItem", 0, this->Element);
if(!select){
XdmfErrorMessage("Section = DataItem but DataItem == 0");
delete [] attribute;
return(XDMF_FAIL);
}
}else{
......@@ -481,6 +484,7 @@ if( this->GridType & XDMF_GRID_MASK){
}
}
delete [] attribute;
target = this->Children[0];
if(!target){
XdmfErrorMessage("No Target Grid Spceified for Subset");
......@@ -564,6 +568,7 @@ if( this->NumberOfAttributes > 0 ){
this->NumberOfAttributes * sizeof( XdmfAttribute * ));
for( Index = 0 ; Index < this->NumberOfAttributes ; Index++ ){
iattribute = new XdmfAttribute;
iattribute->SetDeleteOnGridDelete(true);
this->Attribute[Index] = iattribute;
if (Index == 0) {
AttributeElement = this->DOM->FindElement( "Attribute", Index, this->Element );
......
......@@ -116,7 +116,7 @@ XdmfSet::Build(){
di->SetArray(this->Ids);
if(this->Ids->GetNumberOfElements() > 100) di->SetFormat(XDMF_FORMAT_HDF);
di->Build();
delete di;
}
return(XDMF_SUCCESS);
}
......
......@@ -106,6 +106,7 @@ XdmfTopology::Build(){
di->SetArray(this->Connectivity);
if(this->Connectivity->GetNumberOfElements() > this->LightDataLimit) di->SetFormat(XDMF_FORMAT_HDF);
di->Build();
delete di;
}
return(XDMF_SUCCESS);
}
......@@ -584,17 +585,21 @@ Attribute = this->Get( "TopologyType" );
if(!Attribute) Attribute = this->Get( "Type" );
if( this->SetTopologyTypeFromString( Attribute ) == XDMF_FAIL ){
XdmfErrorMessage("Bad Topology Type : " << Attribute );
delete [] Attribute;
return( XDMF_FAIL );
}
delete [] Attribute;
// Set Shape Either Way
Attribute = this->Get( "NumberOfElements" );
if( Attribute ){
this->GetShapeDesc()->SetShapeFromString( Attribute );
}
delete [] Attribute;
Attribute = this->Get( "Dimensions" );
if( Attribute ){
this->GetShapeDesc()->SetShapeFromString( Attribute );
}
delete [] Attribute;
Attribute = this->Get( "NodesPerElement" );
if( Attribute ){
XdmfInt64 nodesPerElement;
......@@ -602,14 +607,17 @@ if( Attribute ){
nodesPerElement = strtol( Attribute, (XdmfString *)NULL, 0 );
this->SetNodesPerElement( nodesPerElement );
}
delete [] Attribute;
Attribute = this->Get( "Order" );
if( Attribute ){
this->SetOrderFromString( Attribute );
}
delete [] Attribute;
Attribute = this->Get( "BaseOffset" );
if( Attribute ){
this->BaseOffset = strtol( Attribute, (XdmfString *)NULL, 0);
}
delete [] Attribute;
if(!this->Name) this->SetName(GetUnique("Topology_"));
return( XDMF_SUCCESS );
}
......
......@@ -57,14 +57,15 @@ XdmfValues::Inherit(XdmfDataItem *DataItem) {
XdmfErrorMessage("Error Setting Element");
return(XDMF_FAIL);
}
if(this->DataDesc && this->DataDescIsMine){
delete this->DataDesc;
}
this->DataDescIsMine = 0;
//if(this->DataDesc && this->DataDescIsMine){
// delete this->DataDesc;
//}
//this->DataDescIsMine = 0;
if(this->SetDataDesc(DataItem->GetDataDesc()) != XDMF_SUCCESS){
XdmfErrorMessage("Error Setting DataDesc");
return(XDMF_FAIL);
}
//this->DataDescIsMine = 0;
return(XDMF_SUCCESS);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment