gnucash master: Clear the option slots the right way.

John Ralls jralls at code.gnucash.org
Mon Jul 6 16:57:00 EDT 2015


Updated	 via  https://github.com/Gnucash/gnucash/commit/919fe76c (commit)
	from  https://github.com/Gnucash/gnucash/commit/133f03d4 (commit)



commit 919fe76c95faece9b227227aa75aea1496acfdeb
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Jul 6 13:55:13 2015 -0700

    Clear the option slots the right way.
    
    Deleting the frame leaves the value with an invalid pointer.

diff --git a/src/libqof/qof/kvp_frame.cpp b/src/libqof/qof/kvp_frame.cpp
index d38eedf..4fa33d6 100644
--- a/src/libqof/qof/kvp_frame.cpp
+++ b/src/libqof/qof/kvp_frame.cpp
@@ -56,6 +56,17 @@ KvpFrameImpl::KvpFrameImpl(const KvpFrameImpl & rhs) noexcept
     );
 }
 
+KvpFrameImpl::~KvpFrameImpl() noexcept
+{
+    std::for_each(m_valuemap.begin(), m_valuemap.end(),
+		 [](const map_type::value_type &a){
+		      qof_string_cache_remove(a.first);
+		      delete a.second;
+		  }
+	);
+    m_valuemap.clear();
+}
+
 static inline Path
 make_vector(std::string key)
 {
diff --git a/src/libqof/qof/kvp_frame.hpp b/src/libqof/qof/kvp_frame.hpp
index f765a6d..949709f 100644
--- a/src/libqof/qof/kvp_frame.hpp
+++ b/src/libqof/qof/kvp_frame.hpp
@@ -115,6 +115,11 @@ struct KvpFrameImpl
     KvpFrameImpl(const KvpFrameImpl &) noexcept;
 
     /**
+     * Perform a deep delete.
+     */
+    ~KvpFrameImpl() noexcept;
+
+    /**
      * Set the value with the key in the immediate frame, replacing and
      * returning the old value if it exists or nullptr if it doesn't.
      * @param key: The key to insert/replace.
diff --git a/src/libqof/qof/qofbook.cpp b/src/libqof/qof/qofbook.cpp
index e34ee08..3579b05 100644
--- a/src/libqof/qof/qofbook.cpp
+++ b/src/libqof/qof/qofbook.cpp
@@ -1140,9 +1140,7 @@ void
 qof_book_options_delete (QofBook *book)
 {
     KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
-    auto option = root->get_slot(KVP_OPTION_PATH);
-    if (option != nullptr)
-        delete option->get<KvpFrame*>();
+    delete root->set_path(KVP_OPTION_PATH, nullptr);
 }
 
 /* QofObject function implementation and registration */



Summary of changes:
 src/libqof/qof/kvp_frame.cpp | 11 +++++++++++
 src/libqof/qof/kvp_frame.hpp |  5 +++++
 src/libqof/qof/qofbook.cpp   |  4 +---
 3 files changed, 17 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list