diff --git a/dw/layout.cc b/dw/layout.cc index 82b0feb..aef5ec0 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -327,10 +327,8 @@ Layout::~Layout () if (bgImage) bgImage->unref (); if (topLevel) { - detachWidget (topLevel); - Widget *w = topLevel; - topLevel = NULL; - delete w; + detachWidget (topLevel.get()); + topLevel.reset(); } delete queueResizeList; @@ -379,7 +377,9 @@ void Layout::addWidget (Widget *widget) widget->stackingContextWidget = widget; } - topLevel = widget; + std::unique_ptr< Widget > widget_unique; + widget_unique.reset( widget ); + topLevel = std::move( widget_unique ); widget->layout = this; widget->container = NULL; DBG_OBJ_SET_PTR_O (widget, "container", widget->container); @@ -432,9 +432,7 @@ void Layout::setWidget (Widget *widget) widgetAtPoint = NULL; if (topLevel) { - Widget *w = topLevel; - topLevel = NULL; - delete w; + topLevel.reset(); } textZone->zoneFree (); addWidget (widget); diff --git a/dw/layout.hh b/dw/layout.hh index 8389b3a..757ce3a 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -158,7 +158,8 @@ private: Platform *platform; View *view; - Widget *topLevel, *widgetAtPoint; + std::unique_ptr< Widget > topLevel; + Widget *widgetAtPoint; lout::container::typed::Vector *queueResizeList; /* The state, which must be projected into the view. */ diff --git a/dw/widget.cc b/dw/widget.cc index 79ea4be..8874f70 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -214,7 +214,7 @@ void Widget::drawInterruption (View *view, Rectangle *area, DrawingContext *context) { Rectangle thisArea; - if (intersects (layout->topLevel, context->getToplevelArea (), &thisArea)) + if (intersects (layout->topLevel.get(), context->getToplevelArea (), &thisArea)) draw (view, &thisArea, context); context->addWidgetProcessedAsInterruption (this);