Uploaded image for project: 'HPCC'
  1. HPCC
  2. HPCC-27443

Use of a shared_ptr of a base class, where base class has no virtual destructor

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Not specified
    • Resolution: Fixed
    • None
    • 8.6.16
    • JLib
    • None

    Description

      The metric code uses

      std::shared_ptr<IMetric>

      but they are created as

      std::shared_ptr<CounterMetric>

      However IMetric does not have a virtual destructor which means the objects will not be cleaned up properly (undefined behaviour). It may be the cause of the recent crashes we have seen.

      I'm also not 100% clear whether the following is completely legal

      std::shared_ptr<base> x = std::shared_ptr<derived>

      Does it use the same shared_ptr? Is it cleaned up properly. It compiles without problem, so I suspect it is ok - provided base has a virtual destructor.

      Attachments

        Issue Links

          Activity

            People

              ghalliday Gavin Halliday
              ghalliday Gavin Halliday
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: