]> git.notmuchmail.org Git - notmuch/commitdiff
lib: call g_mime_init() from notmuch_database_open()
authorKazuo Teramoto <kaz.rag@gmail.com>
Sat, 31 Dec 2011 04:37:41 +0000 (02:37 -0200)
committerDavid Bremner <bremner@debian.org>
Sun, 1 Jan 2012 03:08:15 +0000 (23:08 -0400)
As reported in
id:"CAEbOPGyuHnz4BPtDutnTPUHcP3eYcRCRkXhYoJR43RUMw671+g@mail.gmail.com"
sometimes gmime tries to access a NULL pointer, e.g. g_mime_iconv_open()
tries to access iconv_cache that is NULL if g_mime_init() is not called.
This causes notmuch to segfault when calling gmime functions.

Calling g_mime_init() initializes iconv_cache and others variables needed
by gmime, making sure they are initialized when notmuch calls gmime
functions.

Test marked fix by db.

lib/database.cc
test/python

index d11dfaf3dc7245b6b0f7988f5056144e318d8dd4..8103bd96ef88c0e30f256753145f17f5583118a2 100644 (file)
@@ -28,6 +28,8 @@
 #include <glib.h> /* g_free, GPtrArray, GHashTable */
 #include <glib-object.h> /* g_type_init */
 
+#include <gmime/gmime.h> /* g_mime_init */
+
 using namespace std;
 
 #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
@@ -585,6 +587,7 @@ notmuch_database_open (const char *path,
     struct stat st;
     int err;
     unsigned int i, version;
+    static int initialized = 0;
 
     if (asprintf (&notmuch_path, "%s/%s", path, ".notmuch") == -1) {
        notmuch_path = NULL;
@@ -608,6 +611,12 @@ notmuch_database_open (const char *path,
     /* Initialize the GLib type system and threads */
     g_type_init ();
 
+    /* Initialize gmime */
+    if (! initialized) {
+       g_mime_init (0);
+       initialized = 1;
+    }
+
     notmuch = talloc (NULL, notmuch_database_t);
     notmuch->exception_reported = FALSE;
     notmuch->path = talloc_strdup (notmuch, path);
index 0b56db30610af9327e9c3c8b1e99591ab8544e56..c3aa7266e285f0e6b6f4b2671ffed07663eab805 100755 (executable)
@@ -5,7 +5,6 @@ test_description="python bindings"
 add_email_corpus
 
 test_begin_subtest "compare thread ids"
-test_subtest_known_broken
 test_python <<EOF
 import notmuch
 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)