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