--- /dev/null
+Return-Path: <kaz.rag@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 9DD6C429E30\r
+ for <notmuch@notmuchmail.org>; Fri, 30 Dec 2011 20:37:58 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id NTCXQMuUA1-u for <notmuch@notmuchmail.org>;\r
+ Fri, 30 Dec 2011 20:37:57 -0800 (PST)\r
+Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com\r
+ [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 9CDEE431FD0\r
+ for <notmuch@notmuchmail.org>; Fri, 30 Dec 2011 20:37:57 -0800 (PST)\r
+Received: by mail-qy0-f181.google.com with SMTP id a6so11114857qch.26\r
+ for <notmuch@notmuchmail.org>; Fri, 30 Dec 2011 20:37:57 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=ROaKvGrTyuvu7oQ9Z0Wa8lBbgByBYdnrWCWklE0S29A=;\r
+ b=N3LvO4Xw7ZpE5YKGnEMG4W3LgLZphPTMO0oOVCquCgidZ8H3F52QCri3ivXIxazNLD\r
+ 33ndg+la8nEexxkHRFRpYxJMeo8zBndzcc4cjKSNaWjeET2K/VKtyMkt4/aNImaUF7ht\r
+ nweOzN3h8QnjPbQsVy0Gl7NpylAWav+F2T7Lk=\r
+Received: by 10.224.42.10 with SMTP id q10mr33145579qae.26.1325306277270;\r
+ Fri, 30 Dec 2011 20:37:57 -0800 (PST)\r
+Received: from localhost.localdomain (201-1-35-143.dsl.telesp.net.br.\r
+ [201.1.35.143])\r
+ by mx.google.com with ESMTPS id r10sm76863833qaz.7.2011.12.30.20.37.55\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Fri, 30 Dec 2011 20:37:56 -0800 (PST)\r
+From: Kazuo Teramoto <kaz.rag@gmail.com>\r
+To: david@tethera.net,\r
+ notmuch@notmuchmail.org\r
+Subject: [PATCH] lib: call g_mime_init() from notmuch_database_open()\r
+Date: Sat, 31 Dec 2011 02:37:41 -0200\r
+Message-Id: <1325306261-21444-2-git-send-email-kaz.rag@gmail.com>\r
+X-Mailer: git-send-email 1.7.8.1\r
+In-Reply-To: <1325306261-21444-1-git-send-email-kaz.rag@gmail.com>\r
+References: <87hb0h5tps.fsf@zancas.localnet>\r
+ <1325306261-21444-1-git-send-email-kaz.rag@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 31 Dec 2011 04:37:59 -0000\r
+\r
+As reported in\r
+id:"CAEbOPGyuHnz4BPtDutnTPUHcP3eYcRCRkXhYoJR43RUMw671+g@mail.gmail.com"\r
+sometimes gmime try to access a NULL pointer, e.g. g_mime_iconv_open()\r
+try to access iconv_cache that is NULL if g_mime_init() is not called.\r
+This cause notmuch to segfault when calling gmime functions.\r
+\r
+Calling g_mime_init() initialize iconv_cache and others variables needed\r
+by gmime, making sure they are initialized when notmuch calls gmime\r
+functions.\r
+---\r
+ lib/database.cc | 9 +++++++++\r
+ 1 files changed, 9 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index d11dfaf..8103bd9 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -28,6 +28,8 @@\r
+ #include <glib.h> /* g_free, GPtrArray, GHashTable */\r
+ #include <glib-object.h> /* g_type_init */\r
+ \r
++#include <gmime/gmime.h> /* g_mime_init */\r
++\r
+ using namespace std;\r
+ \r
+ #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))\r
+@@ -585,6 +587,7 @@ notmuch_database_open (const char *path,\r
+ struct stat st;\r
+ int err;\r
+ unsigned int i, version;\r
++ static int initialized = 0;\r
+ \r
+ if (asprintf (¬much_path, "%s/%s", path, ".notmuch") == -1) {\r
+ notmuch_path = NULL;\r
+@@ -608,6 +611,12 @@ notmuch_database_open (const char *path,\r
+ /* Initialize the GLib type system and threads */\r
+ g_type_init ();\r
+ \r
++ /* Initialize gmime */\r
++ if (! initialized) {\r
++ g_mime_init (0);\r
++ initialized = 1;\r
++ }\r
++\r
+ notmuch = talloc (NULL, notmuch_database_t);\r
+ notmuch->exception_reported = FALSE;\r
+ notmuch->path = talloc_strdup (notmuch, path);\r
+-- \r
+1.7.8.1\r
+\r