[niepce] Notifications: implement drop on Notification to not leak QueriedContent



commit d90823e7c5f4faf804ed2bba67fc778dc612140d
Author: Hubert Figuière <hub figuiere net>
Date:   Thu Oct 26 20:42:31 2017 -0400

    Notifications: implement drop on Notification to not leak QueriedContent

 src/engine/db/libfile.cpp           |    4 ++++
 src/engine/library/notification.hpp |    1 +
 src/engine/library/notification.rs  |   12 ++++++++++++
 3 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/src/engine/db/libfile.cpp b/src/engine/db/libfile.cpp
index 48224f3..700ee9b 100644
--- a/src/engine/db/libfile.cpp
+++ b/src/engine/db/libfile.cpp
@@ -29,6 +29,10 @@ QueriedContent::QueriedContent(library_id_t _container)
 {
 }
 
+QueriedContent::~QueriedContent()
+{
+}
+
 void QueriedContent::push(void* f)
 {
     files->push_back(eng::libfile_wrap(static_cast<LibFile*>(f)));
diff --git a/src/engine/library/notification.hpp b/src/engine/library/notification.hpp
index 698e938..cadf8b5 100644
--- a/src/engine/library/notification.hpp
+++ b/src/engine/library/notification.hpp
@@ -45,6 +45,7 @@ struct QueriedContent {
     LibFileListPtr files;
 
     QueriedContent(library_id_t container);
+    ~QueriedContent();
     // void instead of LibFile because bindgen fail to generate the proper type
     void push(void*);
 };
diff --git a/src/engine/library/notification.rs b/src/engine/library/notification.rs
index 0487274..098777a 100644
--- a/src/engine/library/notification.rs
+++ b/src/engine/library/notification.rs
@@ -102,6 +102,18 @@ pub enum Notification {
     XmpNeedsUpdate,
 }
 
+impl Drop for Notification {
+    fn drop(&mut self) {
+        match *self {
+            Notification::FolderContentQueried(mut c) |
+            Notification::KeywordContentQueried(mut c) => {
+                unsafe { c.destruct(); }
+            },
+            _ => (),
+        }
+    }
+}
+
 #[cfg(not(test))]
 #[allow(improper_ctypes)]
 extern "C" {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]