[PATCH] ruby: make sure the database is closed

Felipe Contreras felipe.contreras at gmail.com
Mon Apr 23 05:43:52 PDT 2012


If the Ruby code does not manually close the database, we need to make
sure it's closed when garbage collected.

In Ruby, users are not _required_ to close, the garbage collector should
take care of that.

Signed-off-by: Felipe Contreras <felipe.contreras at gmail.com>
---
 bindings/ruby/database.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index 982fd59..7b2ed47 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -20,10 +20,16 @@
 
 #include "defs.h"
 
+static void
+database_free (void *p)
+{
+    notmuch_database_close (p);
+}
+
 VALUE
 notmuch_rb_database_alloc (VALUE klass)
 {
-    return Data_Wrap_Struct (klass, NULL, NULL, NULL);
+    return Data_Wrap_Struct (klass, NULL, database_free, NULL);
 }
 
 /*
-- 
1.7.10



More information about the notmuch mailing list