Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 6481D431FD0 for ; Mon, 2 Jan 2012 04:56:22 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] 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 PspL-I9nijmo for ; Mon, 2 Jan 2012 04:56:21 -0800 (PST) Received: from mail-gw3.nixu.fi (mail-gw3.nixu.fi [193.209.237.7]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 58009431FB6 for ; Mon, 2 Jan 2012 04:56:21 -0800 (PST) Received: from pps.filterd (mail-gw3 [127.0.0.1]) by mail-gw3.nixu.fi (8.14.4/8.14.4) with SMTP id q02CqwbU004513; Mon, 2 Jan 2012 14:56:15 +0200 Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) by mail-gw3.nixu.fi with ESMTP id 114cs0wwnv-1 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Mon, 02 Jan 2012 14:56:15 +0200 Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id q02CuDPa028402; Mon, 2 Jan 2012 14:56:14 +0200 From: Tomi Ollila To: David Bremner , Kazuo Teramoto , notmuch@notmuchmail.org Subject: Re: [PATCH 2/2] lib: call g_mime_init from notmuch_database_open In-Reply-To: <87hb0h5tps.fsf@zancas.localnet> References: <877h1e6r9d.fsf@zancas.localnet> <1325282290-29565-1-git-send-email-kaz.rag@gmail.com> <1325282290-29565-3-git-send-email-kaz.rag@gmail.com> <87hb0h5tps.fsf@zancas.localnet> User-Agent: Notmuch/0.10.2+157~g442d405 (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.5.7110, 1.0.211, 0.0.0000 definitions=2012-01-02_03:2012-01-02, 2012-01-02, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=2 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1012030000 definitions=main-1201020078 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: Mon, 02 Jan 2012 12:56:22 -0000 On Fri, 30 Dec 2011 23:02:39 -0400, David Bremner wrote: > On Fri, 30 Dec 2011 19:58:10 -0200, Kazuo Teramoto wrote: > > We need to call g_mime_init to correct initialize the structures needed > > by gmime before using it. > > --- > > lib/database.cc | 5 +++++ > > 1 files changed, 5 insertions(+), 0 deletions(-) > > I can confirm this patch (alone) fixes the segfault for me. and doesn't > cause in test failures when applied against the release branch. I'm > considering pushing it into the 0.11 release. Any comments on that? Do it. The current implementation does not break anything (in our case as we don't do g_mime_shutdown() (0, 1 or 2 times)... The usage needs to be "fixed" soon after... > d .. my suggestions how to fix this: 1) just call g_mime_init(0) without checking whether it is initialized already. As it't return type is 'void' it can be expected to keep some global storage (and reference count...). If it returned something else it either returns common (singleton) instance (and keeps reference count) or returns new instance each time called.... Never call g_mime_shutdown(); just let operating system free resources when program exits. The first lines in g_mime_shutdown(): if (--initialized) return; looks a bit suspicious -- what if application happens to call g_mime_shutdown() too often and then trying to call g_mime_init() again... 2) create function void notmuch_g_type_init (void) { static int initialized; if (initialized++) return; g_mime_init(0) atexit (g_mime_shutdown); } and use that in place of g_mime_init() always (perhaps use macro trickery to disallow g_mime_init (and g_mime_shutdown). Note that although atexit() makes pretty sure that in normal exit g_mime_shutdown() is called due to various reasons that normal exit case is not reached (dies by signal, usage of _exit, execve(2) hardware failure, lost power etc.)(*). Therefore, IMO, I'd leave this (particular) cleanup to be done by the operating system -- less, simpler application code. Tomi (*) I recall reading an article about 'design for failure' or 'expect failure' like 5 years ago but cannot find it anymore. The point on that article was that software can fail in any point (specially, compare man 2 rename and then around lines 580-610 in http://git.busybox.net/busybox/tree/sysklogd/syslogd.c ). Since then I've tried to prioritize in finalize things that matter early and leave operating system to do other cleanpus for me (why do something yourself that machine can do for you). Did you know that doing full windows reboot is faster if the machine is just unplugged from power source for a second and then restarted instead of doing "clean" reboot cycle. Linux boots so fast I don't know if I'd notice the difference ;)