From 478968c137e66c873d69e569dbca892e4971cfe7 Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Tue, 4 Oct 2016 17:59:17 +0200 Subject: [PATCH 1/3] trivial: init all private object members of the database in qt in particular this allows catching nullptr access on the ptr member --- qt/database.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qt/database.cpp b/qt/database.cpp index 390eba8c..fa505dec 100644 --- a/qt/database.cpp +++ b/qt/database.cpp @@ -42,7 +42,11 @@ using namespace Appstream; class Appstream::DatabasePrivate { public: - DatabasePrivate(const QString& cachePath) : m_cachePath(cachePath) { + DatabasePrivate(const QString& cachePath) + : m_cachePath(cachePath) + , m_errorString() + , m_dpool(nullptr) + { } QString m_cachePath; From 49daa955c5eece5e457e8435db99f30b0f144818 Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Tue, 4 Oct 2016 16:53:05 +0200 Subject: [PATCH 2/3] qt: nullptr access on unopened databases resulting in a crash --- qt/database.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qt/database.cpp b/qt/database.cpp index fa505dec..517e8ca4 100644 --- a/qt/database.cpp +++ b/qt/database.cpp @@ -71,7 +71,8 @@ class Appstream::DatabasePrivate { } ~DatabasePrivate() { - g_object_unref (m_dpool); + if (m_dpool) + g_object_unref (m_dpool); } }; From 784b10f53f87d194ed7db8960f2984b2b925d007 Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Tue, 4 Oct 2016 17:47:18 +0200 Subject: [PATCH 3/3] qt: stop leaking as_pool instances - only open once - roll back on pool loading errors by unrefing the pool instance again --- qt/database.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qt/database.cpp b/qt/database.cpp index 517e8ca4..d58537c5 100644 --- a/qt/database.cpp +++ b/qt/database.cpp @@ -54,6 +54,9 @@ class Appstream::DatabasePrivate { AsPool *m_dpool; bool open() { + if (m_dpool) + return true; // Already open! + g_autoptr(GError) error = NULL; m_dpool = as_pool_new (); @@ -64,6 +67,8 @@ class Appstream::DatabasePrivate { as_pool_load_cache_file (m_dpool, qPrintable(m_cachePath), &error); if (error != NULL) { m_errorString = QString::fromUtf8 (error->message); + g_object_unref (m_dpool); + m_dpool = nullptr; return false; }