[PATCH 4/7] go: Make Destroy functions safe to call several times

Adrien Bustany adrien at bustany.org
Wed Jul 18 11:34:32 PDT 2012


Those methods were already checking if the underlying C object was NULL,
but they were not setting the pointer to NULL after destroying it.
---
 bindings/go/src/notmuch/notmuch.go |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/bindings/go/src/notmuch/notmuch.go b/bindings/go/src/notmuch/notmuch.go
index 3f436a0..d8b2739 100644
--- a/bindings/go/src/notmuch/notmuch.go
+++ b/bindings/go/src/notmuch/notmuch.go
@@ -634,6 +634,7 @@ func (self *Query) SearchMessages() *Messages {
 func (self *Query) Destroy() {
 	if self.query != nil {
 		C.notmuch_query_destroy(self.query)
+		self.query = nil
 	}
 }
 
@@ -680,6 +681,7 @@ func (self *Threads) Valid() bool {
 func (self *Threads) Destroy() {
 	if self.threads != nil {
 		C.notmuch_threads_destroy(self.threads)
+		self.threads = nil
 	}
 }
 
@@ -1143,6 +1145,7 @@ func (self *Message) Destroy() {
 		return
 	}
 	C.notmuch_message_destroy(self.message)
+	self.message = nil
 }
 
 /* Is the given 'tags' iterator pointing at a valid tag.
@@ -1214,6 +1217,7 @@ func (self *Tags) Destroy() {
 		return
 	}
 	C.notmuch_tags_destroy(self.tags)
+	self.tags = nil
 }
 
 // TODO: wrap notmuch_directory_<fct>
@@ -1224,6 +1228,7 @@ func (self *Directory) Destroy() {
 		return
 	}
 	C.notmuch_directory_destroy(self.dir)
+	self.dir = nil
 }
 
 // TODO: wrap notmuch_filenames_<fct>
@@ -1242,6 +1247,7 @@ func (self *Filenames) Destroy() {
 		return
 	}
 	C.notmuch_filenames_destroy(self.fnames)
+	self.fnames = nil
 }
 
 /* EOF */
-- 
1.7.7.6



More information about the notmuch mailing list