Skip to content

Commit

Permalink
protect against multiple initialize() calls leaking streams
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Jun 5, 2015
1 parent 7a88142 commit c620ac3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions io/las/LasReader.cpp
Expand Up @@ -141,6 +141,7 @@ QuickInfo LasReader::inspect()

void LasReader::initialize()
{
if (m_initialized) return;
m_istream = createStream();

m_istream->seekg(0);
Expand Down Expand Up @@ -177,6 +178,7 @@ void LasReader::initialize()
readExtraBytesVlr();
}
fixupVlrs();
m_initialized = true;
}


Expand Down
10 changes: 9 additions & 1 deletion io/las/LasReader.hpp
Expand Up @@ -57,7 +57,7 @@ class PDAL_DLL LasReader : public pdal::Reader
{
friend class NitfReader;
public:
LasReader() : pdal::Reader(), m_index(0), m_istream(NULL)
LasReader() : pdal::Reader(), m_index(0), m_istream(NULL), m_initialized(false)
{}

virtual ~LasReader()
Expand All @@ -78,6 +78,13 @@ class PDAL_DLL LasReader : public pdal::Reader
virtual std::istream *createStream()
{
m_istream = FileUtils::openFile(m_filename);
if (!m_istream)
{
std::ostringstream oss;
oss << "Unable to create open stream for '"
<< m_filename <<"' with error '" << strerror(errno) <<"'";
throw pdal_error(oss.str());
}
return m_istream;
}
virtual void destroyStream()
Expand Down Expand Up @@ -122,6 +129,7 @@ class PDAL_DLL LasReader : public pdal::Reader

LasReader& operator=(const LasReader&); // not implemented
LasReader(const LasReader&); // not implemented
bool m_initialized;
};

} // namespace pdal

0 comments on commit c620ac3

Please sign in to comment.