Uploaded image for project: 'ORC'
  1. ORC
  2. ORC-586

[C++] Memory leak in StructColumnReader

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.6.3, 1.7.0
    • None
    • None

    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:

      https://github.com/apache/orc/blob/c26ff4c351d7c34c4272442a6874703f510282a8/c%2B%2B/src/ColumnReader.cc#L874

        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

          Activity

            People

              boroknagyz Zoltán Borók-Nagy
              boroknagyz Zoltán Borók-Nagy
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m