瀏覽代碼

Fix memory leak associated with ctkDoubleSpinBox ensuring pimpl is deleted

This commit fixes the following error reported by valgrind memcheck tool by
using a QScopedPointer.

==29339== 304 (136 direct, 168 indirect) bytes in 1 blocks are definitely lost in loss record 2,065 of 2,448
==29339==    at 0x4C2B0E0: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==29339==    by 0x20AECCE1: QObject::QObject(QObject*) (in /home/jcfr/Support/qt-everywhere-opensource-release-build-4.8.6/lib/libQtCore.so.4.8.6)
==29339==    by 0x88008D8: ctkDoubleSpinBoxPrivate::ctkDoubleSpinBoxPrivate(ctkDoubleSpinBox&) (ctkDoubleSpinBox.cpp:174)
==29339==    by 0x880271F: ctkDoubleSpinBox::ctkDoubleSpinBox(QWidget*) (ctkDoubleSpinBox.cpp:587)
==29339==    by 0x887AB25: Ui_ctkSliderWidget::setupUi(QWidget*) (ui_ctkSliderWidget.h:50)
==29339==    by 0x8877D13: ctkSliderWidget::ctkSliderWidget(QWidget*) (ctkSliderWidget.cpp:175)
==29339==    by 0x5E99878: Ui_qMRMLSliceControllerWidget::setupUi(ctkPopupWidget*) (ui_qMRMLSliceControllerWidget.h:391)
==29339==    by 0x5E8BA8A: qMRMLSliceControllerWidgetPrivate::setupPopupUi() (qMRMLSliceControllerWidget.cxx:128)
==29339==    by 0x5EC28C0: qMRMLViewControllerBarPrivate::init() (qMRMLViewControllerBar.cxx:98)
==29339==    by 0x5E8CB69: qMRMLSliceControllerWidgetPrivate::init() (qMRMLSliceControllerWidget.cxx:328)
==29339==    by 0x5E923BB: qMRMLSliceControllerWidget::qMRMLSliceControllerWidget(QWidget*) (qMRMLSliceControllerWidget.cxx:1237)
==29339==    by 0x5EA70F0: Ui_qMRMLSliceWidget::setupUi(qMRMLWidget*) (ui_qMRMLSliceWidget.h:43)
Jean-Christophe Fillion-Robin 9 年之前
父節點
當前提交
b688b71d75
共有 2 個文件被更改,包括 9 次插入3 次删除
  1. 5 0
      Libs/Widgets/ctkDoubleSpinBox.cpp
  2. 4 3
      Libs/Widgets/ctkDoubleSpinBox.h

+ 5 - 0
Libs/Widgets/ctkDoubleSpinBox.cpp

@@ -601,6 +601,11 @@ ctkDoubleSpinBox::ctkDoubleSpinBox(ctkDoubleSpinBox::SetMode mode, QWidget* newP
 }
 
 //-----------------------------------------------------------------------------
+ctkDoubleSpinBox::~ctkDoubleSpinBox()
+{
+}
+
+//-----------------------------------------------------------------------------
 double ctkDoubleSpinBox::value() const
 {
   Q_D(const ctkDoubleSpinBox);

+ 4 - 3
Libs/Widgets/ctkDoubleSpinBox.h

@@ -161,8 +161,9 @@ public:
 
   /// Constructor, creates a ctkDoubleSpinBox. The look and feel
   /// are the same as of a QDoubleSpinBox
-  ctkDoubleSpinBox(QWidget* parent = 0);
-  ctkDoubleSpinBox(ctkDoubleSpinBox::SetMode mode, QWidget* parent = 0);
+  explicit ctkDoubleSpinBox(QWidget* parent = 0);
+  explicit ctkDoubleSpinBox(ctkDoubleSpinBox::SetMode mode, QWidget* parent = 0);
+  virtual ~ctkDoubleSpinBox();
 
   /// Get the spinbox current value
   /// \sa setValue(), cleanText()
@@ -319,7 +320,7 @@ Q_SIGNALS:
   void decimalsChanged(int);
 
 protected:
-  ctkDoubleSpinBoxPrivate* const d_ptr;
+  QScopedPointer<ctkDoubleSpinBoxPrivate> d_ptr;
 
   /// Reimplemented to support shortcuts.
   virtual void keyPressEvent(QKeyEvent* event);