Skip to content

Commit

Permalink
Merge pull request #68 from LLNL/bugfix/weiss27/sidre-attributes
Browse files Browse the repository at this point in the history
Fixes some sidre memory leaks
  • Loading branch information
kennyweiss committed Jul 24, 2019
2 parents 76e86a2 + 54ae1a1 commit cbc05a2
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 17 deletions.
8 changes: 7 additions & 1 deletion src/axom/sidre/core/AttrValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,13 @@ AttrValues::AttrValues() :
*************************************************************************
*/
AttrValues::~AttrValues()
{}
{
if(m_values != nullptr)
{
delete m_values;
m_values = nullptr;
}
}

} /* end namespace sidre */
} /* end namespace axom */
2 changes: 1 addition & 1 deletion src/axom/sidre/core/AttrValues.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class AttrValues

///////////////////////////////////////////////////////////////////
//
typedef std::vector< Node > Values;
using Values = std::vector< Node >;
///////////////////////////////////////////////////////////////////

/// Attributes values.
Expand Down
1 change: 1 addition & 0 deletions src/axom/sidre/core/DataStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ DataStore::~DataStore()
// clean up Groups and Views before we destroy Buffers
delete m_RootGroup;
destroyAllBuffers();
destroyAllAttributes();
delete m_attribute_coll;

if ( m_need_to_finalize_slic )
Expand Down
2 changes: 1 addition & 1 deletion src/axom/sidre/core/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "conduit_relay.hpp"

#ifdef AXOM_USE_HDF5
#include "conduit_relay_hdf5.hpp"
#include "conduit_relay_io_hdf5.hpp"
#endif

// Other axom component headers
Expand Down
8 changes: 4 additions & 4 deletions src/axom/sidre/examples/sidre_createdatastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* create_datastore -- Builds a DataStore containing various Groups,
* Views, Buffers, and Attributes
*
*
* create_tiny_datastore -- Builds a DataStore that holds a small 3D mesh
* conforming to the conduit mesh blueprint
*
Expand All @@ -30,13 +30,13 @@
* generate_blueprint -- Generates a blueprint index and writes data
* to file using Sidre DataStore and Group calls
*
* generate_blueprint_to_path -- Similar to above, but uses path arguments to
* generate_blueprint_to_path -- Similar to above, but uses path arguments to
* find data deeper in Sidre hierarchy
*
* generate_spio_blueprint -- Uses SPIO/IOManager calls to write data to
* file and generate blueprint index
*
* generate_blueprint_to_path -- Similar to above, but uses path arguments to
*
* generate_blueprint_to_path -- Similar to above, but uses path arguments to
* find data deeper in Sidre hierarchy
*/

Expand Down
5 changes: 3 additions & 2 deletions src/axom/sidre/spio/IOManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "conduit_relay.hpp"

#ifdef AXOM_USE_HDF5
#include "conduit_relay_hdf5.hpp"
#include "conduit_relay_io_hdf5.hpp"
#include "hdf5.h"
#endif

Expand Down Expand Up @@ -1092,7 +1092,8 @@ void IOManager::writeBlueprintIndexToRootFile(DataStore* datastore,

//The final name in mesh_path will be used as the name of the
//blueprint index.
conduit::utils::rsplit_string(mesh_path, delimiter, blueprint_name, path_to_mesh);
conduit::utils::rsplit_string(mesh_path, delimiter,
blueprint_name, path_to_mesh);

std::string bp_index("blueprint_index/" + blueprint_name);

Expand Down
2 changes: 1 addition & 1 deletion src/axom/sidre/spio/IOManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class IOManager
*
* If write() is called using the Group located at "/hierarchy/domain_data",
* then only the Groups and Views descending from that Group are written
* to the file. To call this method, we would choose the full path in
* to the file. To call this method, we would choose the full path in
* the DataStore "hierarchy/domain_data/domain/blueprint_mesh" for
* domain_path. For the mesh_path argument, we choose only the path that
* exists in the file: "domain/blueprint_mesh".
Expand Down
2 changes: 2 additions & 0 deletions src/axom/sidre/tests/sidre_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ TEST(sidre_attribute, loop_attributes)
}

// XXX - now delete attribute and check again

delete ds;
}

//------------------------------------------------------------------------------
Expand Down
18 changes: 16 additions & 2 deletions src/axom/sidre/tests/sidre_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ TEST(sidre_group,get_name)

Group* group2 = root->getGroup("foo");
EXPECT_TRUE(group2 == nullptr);

delete ds;
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -112,6 +114,8 @@ TEST(sidre_group,get_path_name)
EXPECT_EQ(group->getName(), std::string("c") );
EXPECT_EQ(group->getPath(), std::string("test/a/b") );
EXPECT_EQ(group->getPathName(), std::string("test/a/b/c") );

delete ds;
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -183,7 +187,6 @@ TEST(sidre_group,group_with_path)
EXPECT_EQ(group_testa->getGroup("testb")->getNumGroups(), testbnumgroups);

delete ds;

}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1224,6 +1227,7 @@ TEST(sidre_group,save_restore_api)

EXPECT_TRUE( load1->isEquivalentTo( load2) );

delete ds_new;
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1316,6 +1320,7 @@ TEST(sidre_group,rename_group)
EXPECT_EQ(root, root->getParent());
EXPECT_EQ("newroot", root->getName());

delete ds;
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1676,7 +1681,16 @@ TEST(sidre_group,save_restore_other)
root1->createView("empty_described", INT_ID, ndata);
root1->createView("empty_shape", INT_ID, 2, shape1);

root1->createViewAndAllocate("buffer_shape", INT_ID, 2, shape1);
auto* view = root1->createViewAndAllocate("buffer_shape", INT_ID, 2, shape1);

// fill the data
{
int* data = view->getData();
for(int i=0 ; i< ndata * 2 ; ++i)
{
data[i] = i;
}
}

for (int i = 0 ; i < nprotocols ; ++i)
{
Expand Down
19 changes: 15 additions & 4 deletions src/axom/sidre/tests/sidre_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ TEST(sidre_view,get_path_name)
EXPECT_EQ(std::string("v3"), v3->getPathName());

EXPECT_EQ(1, v4->getIndex());

delete ds;
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -570,11 +572,19 @@ TEST(sidre_view,save_empty_view_non_empty_buffer)
DataStore ds;
Group* root = ds.getRoot();

Buffer* buf = ds.createBuffer(INT_ID, 10)->allocate(); // allocate non-empty
// buffer
// allocate non-empty buffer
const int SZ = 10;
Buffer* buf = ds.createBuffer(INT_ID, SZ)->allocate();

// attach zero-sized array to it
root->createView("a")->attachBuffer(buf)->apply(0);

root->createView("a")->attachBuffer(buf)->apply(0); // attach zero-sized
// array to it
// fill the buffer
int* data = buf->getData();
for(int i=0 ; i< SZ ; ++i)
{
data[i] = i;
}

root->save("empty_view_non_empty_buffer.sidre.json", "sidre_json"); // ok
#ifdef AXOM_USE_HDF5
Expand Down Expand Up @@ -1611,6 +1621,7 @@ TEST(sidre_view,rename_view)
EXPECT_FALSE( success );
EXPECT_TRUE( v3->getName() == "v_c" );

delete ds;
}

//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/axom/sidre/tests/spio/spio_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "conduit_relay.hpp"

#ifdef AXOM_USE_HDF5
#include "conduit_relay_hdf5.hpp"
#include "conduit_relay_io_hdf5.hpp"
#endif

#include "axom/sidre/core/sidre.hpp"
Expand Down

0 comments on commit cbc05a2

Please sign in to comment.