Description
StructColumnReader can leak memory if its constructor throws an exception.
StructColumnReader has a member vector<ColumnReader*> called 'children' which is filled in the constructor:
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()); } }
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.
Attachments
Issue Links
- links to