Zoltán Borók-Nagy created ORC-586:
-------------------------------------
Summary: [C++] Memory leak in StructColumnReader
Key: ORC-586
URL: https://issues.apache.org/jira/browse/ORC-586
Project: ORC
Issue Type: Bug
Reporter: Zoltán Borók-Nagy
StructColumnReader can leak memory if its constructor throws an exception.
StructColumnReader has a member vector<ColumnReader*> called 'children' which
is filled in the constructor:
[https://github.com/apache/orc/blob/c26ff4c351d7c34c4272442a6874703f510282a8/c%2B%2B/src/ColumnReader.cc#L874]
{noformat}
for(unsigned int i=0; i < type.getSubtypeCount(); ++i) { const
Type& child = *type.getSubtype(i); if
(selectedColumns[static_cast<uint64_t>(child.getColumnId())]) {
children.push_back(buildReader(child, stripe).release()); } }
{noformat}
buildReader() returns a unique_ptr, but the constructor calls release() on it
which returns the underlying raw pointer and in the meantime the unique_ptr
releases the ownership.
StructColumnReader's destructor is supposed to invoke delete on these raw
pointers, but if an exception is thrown during the construction of a
StructColumnReader, then only the destructors of the member variables are
called. Therefore the vector gets destroyed, but the ColumnReader objects are
leaked.
The solution is to store unique_ptrs in the vector instead of raw pointers.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)