From: Soeren Apel Date: Sun, 17 Apr 2016 13:28:51 +0000 (+0200) Subject: Fix #705 by preventing the use of invalid instances X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=commitdiff_plain;h=ed2cec68674ac98de6bde7a399d12a0bb9c8dd05 Fix #705 by preventing the use of invalid instances As QCache owns the object instances it manages, inserting an object into the cache transfers ownership automatically. This means we can't use an instance after it has been inserted into the cache as this results in a double free situation as we'd end up calling the destructor on the same object instance as the cache. --- diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 5584a1f..3c85b93 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -449,24 +449,22 @@ void LogicSignal::modify_trigger() const QIcon* LogicSignal::get_icon(const char *path) { - const QIcon *icon = icon_cache_.take(path); - if (!icon) { - icon = new QIcon(path); + if (!icon_cache_.contains(path)) { + const QIcon *icon = new QIcon(path); icon_cache_.insert(path, icon); } - return icon; + return icon_cache_.take(path); } const QPixmap* LogicSignal::get_pixmap(const char *path) { - const QPixmap *pixmap = pixmap_cache_.take(path); - if (!pixmap) { - pixmap = new QPixmap(path); + if (!pixmap_cache_.contains(path)) { + const QPixmap *pixmap = new QPixmap(path); pixmap_cache_.insert(path, pixmap); } - return pixmap; + return pixmap_cache_.take(path); } void LogicSignal::on_trigger()