Commit c52b8783 authored by Dave Moxey's avatar Dave Moxey
Browse files

Fix memory corruption issue, compiler warnings and remove some unnecessary comments

parent 800e89e7
......@@ -115,16 +115,16 @@ const std::string FieldIO::GetFileType(const std::string &filename,
// Read first 8 bytes. If they correspond with magic bytes below it's an
// HDF5 file. XML is potentially a nightmare with all the different
// encodings so we'll just assume it's OK if it's not HDF.
const char magic[8] = {0x89, 0x48, 0x44, 0x46, 0x0d, 0x0a, 0x1a, 0x0a};
const unsigned char magic[8] = {
0x89, 0x48, 0x44, 0x46, 0x0d, 0x0a, 0x1a, 0x0a};
std::ifstream datafile(datafilename.c_str(), ios_base::binary);
char filedata[8];
datafile.read(filedata, 8);
code = 1;
for (unsigned i = 0; i < 8; ++i)
for (unsigned i = 0; i < 8 && datafile.good(); ++i)
{
if (filedata[i] != magic[i])
unsigned char byte = datafile.get();
if (byte != magic[i])
{
code = 0;
break;
......
......@@ -51,10 +51,10 @@ class XmlDataSource : public DataSource
{
public:
/// Default constructor.
XmlDataSource(TiXmlDocument &doc) : m_doc(&doc) { }
XmlDataSource(TiXmlDocument &doc) : m_doc(&doc), m_needsFree(false) { }
/// Constructor based on filename.
XmlDataSource(const std::string &fn)
XmlDataSource(const std::string &fn) : m_needsFree(true)
{
m_doc = new TiXmlDocument(fn);
bool loadOkay = m_doc->LoadFile();
......@@ -69,7 +69,10 @@ public:
/// Destructor cleans up memory usage.
~XmlDataSource()
{
delete m_doc;
if (m_needsFree)
{
delete m_doc;
}
}
/// Return the TinyXML document of this source.
......@@ -99,6 +102,8 @@ public:
private:
/// Internal TinyXML document storage.
TiXmlDocument *m_doc;
/// Boolean dictating whether document needs to be freed or not.
bool m_needsFree;
};
typedef boost::shared_ptr<XmlDataSource> XmlDataSourceSharedPtr;
......
......@@ -479,7 +479,6 @@ ENDIF( NEKTAR_USE_PETSC )
# HDF5
IF( NEKTAR_USE_HDF5 )
MESSAGE(STATUS "LOL: ${HDF5_LIBRARIES}")
TARGET_LINK_LIBRARIES(LibUtilities LINK_PRIVATE ${HDF5_LIBRARIES})
ADD_DEPENDENCIES(LibUtilities hdf5-1.8.16)
ENDIF( NEKTAR_USE_HDF5 )
......
......@@ -123,10 +123,6 @@ namespace Nektar
// Instantiate a field reader/writer
m_fld = LibUtilities::MakeDefaultFieldIO(m_session);
//m_fld = MemoryManager<LibUtilities::FieldIO>
// ::AllocateSharedPtr(
// m_session->GetComm(),
// m_session->DefinesCmdLineArgument("shared-filesystem"));
// Read the geometry and the expansion information
m_graph = SpatialDomains::MeshGraph::Read(m_session);
......
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