From 99c1ac5f4ac2681e2740b076a3ab9c0bcab7817e Mon Sep 17 00:00:00 2001 From: Sebastian Geerken Date: Sun, 2 Mar 2014 11:44:28 +0100 Subject: Two more memory problems. --- dw/layout.cc | 3 +++ dw/textblock.hh | 14 ++++++++++---- dw/widget.cc | 2 +- dw/widget.hh | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dw/layout.cc b/dw/layout.cc index 58b30fb3..542b8ea4 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -308,6 +308,9 @@ Layout::~Layout () if (bgImage) bgImage->unref (); if (topLevel) { + // Sometimes, the toplevel widget does some stuff after the + // layout has been deleted. + topLevel->layout = NULL; Widget *w = topLevel; topLevel = NULL; delete w; diff --git a/dw/textblock.hh b/dw/textblock.hh index e29b93d5..35eea189 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -658,10 +658,16 @@ protected: { if (lines->size() == 0) return 0; - else - return - (words->getRef(lines->getLastRef()->lastWord)->flags & - (Word::DIV_CHAR_AT_EOL | Word::PERM_DIV_CHAR)) ? 1 : 0; + else { + Line *line = lines->getLastRef(); + if (line->firstWord <= line->lastWord) + return + (words->getRef(line->lastWord)->flags & + (Word::DIV_CHAR_AT_EOL | Word::PERM_DIV_CHAR)) ? 1 : 0; + else + // empty line + return 0; + } } Textblock *getTextblockForLine (Line *line); diff --git a/dw/widget.cc b/dw/widget.cc index 8147e3d7..270c5e40 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -106,7 +106,7 @@ Widget::~Widget () if (parent) parent->removeChild (this); - else + else if (layout) layout->removeWidget (); DBG_OBJ_DELETE (); diff --git a/dw/widget.hh b/dw/widget.hh index 8ebc2767..e7ac7f55 100644 --- a/dw/widget.hh +++ b/dw/widget.hh @@ -252,7 +252,7 @@ protected: { layout->changeAnchor (this, name, y); } inline void removeAnchor (char* name) - { layout->removeAnchor (this, name); } + { if (layout) layout->removeAnchor (this, name); } //inline void updateBgColor () { layout->updateBgColor (); } -- cgit v1.2.3