--- /dev/null
+Return-Path: <david@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 1AE446DE0222\r
+ for <notmuch@notmuchmail.org>; Thu, 9 Jun 2016 11:07:10 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.011\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.011 tagged_above=-999 required=5\r
+ tests=[AWL=-0.000, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id Eob_sFdZ8LxG for <notmuch@notmuchmail.org>;\r
+ Thu, 9 Jun 2016 11:07:02 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 6E07A6DE01BE\r
+ for <notmuch@notmuchmail.org>; Thu, 9 Jun 2016 11:07:02 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <david@tethera.net>)\r
+ id 1bB4Lw-0005be-GO; Thu, 09 Jun 2016 14:06:48 -0400\r
+Received: (nullmailer pid 6896 invoked by uid 1000);\r
+ Thu, 09 Jun 2016 18:06:58 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Lars Luthman] Bug#826843: Calls to notmuch_database_add_message()\r
+ after notmuch_database_close() crash\r
+User-Agent: Notmuch/0.22+28~gb9bf3f4 (http://notmuchmail.org) Emacs/24.5.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Thu, 09 Jun 2016 15:06:58 -0300\r
+Message-ID: <87porqxmm5.fsf@tesseract.cs.unb.ca>\r
+MIME-Version: 1.0\r
+Content-Type: message/rfc822\r
+Content-Disposition: inline\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 09 Jun 2016 18:07:10 -0000\r
+\r
+Return-path: <notmuch-bounces@notmuchmail.org>\r
+Envelope-to: david@tethera.net\r
+Delivery-date: Thu, 09 Jun 2016 12:51:04 -0400\r
+Received: from arlo.cworth.org ([50.126.95.6])\r
+ by fethera.tethera.net with esmtp (Exim 4.84)\r
+ (envelope-from <notmuch-bounces@notmuchmail.org>)\r
+ id 1bB3Ae-0004dq-L2\r
+ for david@tethera.net; Thu, 09 Jun 2016 12:51:04 -0400\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 3A8906DE0314;\r
+ Thu, 9 Jun 2016 09:51:10 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id JlCNsTTh5kz0; Thu, 9 Jun 2016 09:51:02 -0700 (PDT)\r
+Received: from arlo.cworth.org (localhost [IPv6:::1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 9F0766DE01C2;\r
+ Thu, 9 Jun 2016 09:50:54 -0700 (PDT)\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 1FD286DE01C2\r
+ for <notmuch@notmuchmail.org>; Thu, 9 Jun 2016 08:44:36 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 8_30yotZM4k9 for <notmuch@notmuchmail.org>;\r
+ Thu, 9 Jun 2016 08:44:27 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id A6EEC6DE01BE\r
+ for <notmuch@notmuchmail.org>; Thu, 9 Jun 2016 08:44:27 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bounces+20160609-bremner=debian.org@tracker.debian.org>)\r
+ id 1bB27w-0003ly-4r\r
+ for notmuch@notmuchmail.org; Thu, 09 Jun 2016 11:44:12 -0400\r
+Received: (nullmailer pid 558 invoked by uid 1000);\r
+ Thu, 09 Jun 2016 15:44:21 -0000\r
+Resent-To: notmuch@notmuchmail.org\r
+Resent-From: David Bremner <david@tethera.net>\r
+Resent-Date: Thu, 09 Jun 2016 12:44:21 -0300\r
+Resent-Message-ID: <87wplyxt7u.fsf@tesseract.cs.unb.ca>\r
+Received: from mailly.debian.org ([2001:41b8:202:deb:6564:a62:52c3:4b72])\r
+ by fethera.tethera.net with esmtp (Exim 4.84)\r
+ (envelope-from <bounces+20160609-bremner=debian.org@tracker.debian.org>)\r
+ id 1bAxjp-0008T2-FK\r
+ for david@tethera.net; Thu, 09 Jun 2016 07:03:01 -0400\r
+Received: from ticharich.debian.org ([2001:41c8:1000:21::21:23])\r
+ from C=NA, ST=NA, L=Ankh Morpork, O=Debian SMTP, OU=Debian SMTP CA,\r
+ CN=ticharich.debian.org, EMAIL=hostmaster@ticharich.debian.org (verified)\r
+ by mailly.debian.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\r
+ (Exim 4.84_2)\r
+ (envelope-from <bounces+20160609-bremner=debian.org@tracker.debian.org>)\r
+ id 1bAxk0-0004GV-Nd\r
+ for david@tethera.net; Thu, 09 Jun 2016 11:03:12 +0000\r
+Received: from localhost ([::1] helo=ticharich.debian.org)\r
+ by ticharich.debian.org with esmtp (Exim 4.84_2)\r
+ (envelope-from <bounces+20160609-bremner=debian.org@tracker.debian.org>)\r
+ id 1bAxk0-00069c-DW\r
+ for david@tethera.net; Thu, 09 Jun 2016 11:03:12 +0000\r
+Received: from muffat.debian.org ([2607:f8f0:610:4000:6564:a62:ce0c:1392])\r
+ from C=NA, ST=NA, L=Ankh Morpork, O=Debian SMTP, OU=Debian SMTP CA,\r
+ CN=muffat.debian.org, EMAIL=hostmaster@muffat.debian.org (verified)\r
+ by ticharich.debian.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\r
+ (Exim 4.84_2) (envelope-from <debbugs@buxtehude.debian.org>)\r
+ id 1bAxk0-00069V-4O\r
+ for dispatch+notmuch@tracker.debian.org; Thu, 09 Jun 2016 11:03:12 +0000\r
+Received: from quantz.debian.org ([2001:41c8:1000:21::21:28])\r
+ from C=NA, ST=NA, L=Ankh Morpork, O=Debian SMTP, OU=Debian SMTP CA,\r
+ CN=quantz.debian.org, EMAIL=hostmaster@quantz.debian.org (verified)\r
+ by muffat.debian.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\r
+ (Exim 4.84_2) (envelope-from <debbugs@buxtehude.debian.org>)\r
+ id 1bAxjx-0005AY-PW\r
+ for dispatch+notmuch@tracker.debian.org; Thu, 09 Jun 2016 11:03:10 +0000\r
+Received: from qa by quantz.debian.org with local (Exim 4.84_2)\r
+ (envelope-from <debbugs@buxtehude.debian.org>) id 1bAxjw-0006ua-BG\r
+ for dispatch+notmuch@tracker.debian.org; Thu, 09 Jun 2016 11:03:08 +0000\r
+Received: from buxtehude.debian.org ([2607:f8f0:610:4000:2015:12:0:147])\r
+ from C=NA, ST=NA, L=Ankh Morpork, O=Debian SMTP, OU=Debian SMTP CA,\r
+ CN=buxtehude.debian.org, EMAIL=hostmaster@buxtehude.debian.org (verified)\r
+ by quantz.debian.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\r
+ (Exim 4.84_2) (envelope-from <debbugs@buxtehude.debian.org>)\r
+ id 1bAxjw-0006tk-4N\r
+ for notmuch@packages.qa.debian.org; Thu, 09 Jun 2016 11:03:08 +0000\r
+Received: from debbugs by buxtehude.debian.org with local (Exim 4.84_2)\r
+ (envelope-from <debbugs@buxtehude.debian.org>)\r
+ id 1bAxjt-0005Bk-Ec; Thu, 09 Jun 2016 11:03:05 +0000\r
+X-Loop: owner@bugs.debian.org\r
+Subject: Bug#826843: Calls to notmuch_database_add_message() after\r
+ notmuch_database_close() crash\r
+Also-Resent-From: Lars Luthman <deb-bugs@larsluthman.net>\r
+Also-Resent-To: debian-bugs-dist@lists.debian.org\r
+Also-Resent-CC: Carl Worth <cworth@debian.org>\r
+X-Loop: owner@bugs.debian.org\r
+Also-Resent-Date: Thu, 09 Jun 2016 11:03:01 +0000\r
+Also-Resent-Message-ID: <handler.826843.B.146547014919804@bugs.debian.org>\r
+X-Debian-PR-Message: report 826843\r
+X-Debian-PR-Package: libnotmuch-dev\r
+X-Debian-PR-Keywords: \r
+X-Debian-PR-Source: notmuch\r
+Received: via spool by submit@bugs.debian.org id=B.146547014919804\r
+ (code B); Thu, 09 Jun 2016 11:03:01 +0000\r
+Received: (at submit) by bugs.debian.org; 9 Jun 2016 11:02:29 +0000\r
+X-Spam-Bayes: score:0.0000 Tokens: new, 47; hammy, 150; neutral, 161; spammy,\r
+ 0. spammytokens: hammytokens:0.000-+--systemd, 0.000-+--deb8u1, \r
+ 0.000-+--H*UA:3.12.9-1, 0.000-+--H*x:3.12.9-1, 0.000-+--en_GButf8\r
+Received: from v-smtpgw2.han.skanova.net ([81.236.60.205])\r
+ by buxtehude.debian.org with esmtp (Exim 4.84_2)\r
+ (envelope-from <deb-bugs@larsluthman.net>) id 1bAxjJ-00058n-Da\r
+ for submit@bugs.debian.org; Thu, 09 Jun 2016 11:02:29 +0000\r
+Received: from miskatonic.local ([78.69.244.232]) by cmsmtp with SMTP\r
+ id Axj9bO3cdctqUAxjAb5kXm; Thu, 09 Jun 2016 13:02:21 +0200\r
+Message-ID: <1465470142.3501.10.camel@larsluthman.net>\r
+From: Lars Luthman <deb-bugs@larsluthman.net>\r
+To: submit@bugs.debian.org\r
+Date: Thu, 09 Jun 2016 13:02:22 +0200\r
+X-Mailer: Evolution 3.12.9-1+b1 \r
+X-CMAE-Envelope: MS4wfMMdDsIM1l3Qa1f8AMdqkBLsZulSFkVnPILa/7bnKy7vEm4kePEgzC6NTWfUzgizPIZAc6sUB2evyOmtpQUgDjqXQ6LEQxTtw+vIUvUyHA7aLhnK00Hl\r
+ FQksKsJl/A76jQ8iymRFjr2C22qm20As/LrAUsbskpt9lKP8xDC8VLW511/i88tLX5zSWk/3fOrzaA==\r
+X-Loop: dispatch@tracker.debian.org\r
+X-Distro-Tracker-Package: notmuch\r
+X-Distro-Tracker-Keyword: bts\r
+X-Debian-Package: notmuch\r
+X-Debian: tracker.debian.org\r
+X-PTS-Package: notmuch\r
+X-PTS-Keyword: bts\r
+Precedence: list\r
+X-Mailman-Approved-At: Thu, 09 Jun 2016 09:50:52 -0700\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+Reply-To: Lars Luthman <deb-bugs@larsluthman.net>, 826843@bugs.debian.org\r
+Errors-To: notmuch-bounces@notmuchmail.org\r
+Sender: "notmuch" <notmuch-bounces@notmuchmail.org>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/mixed; boundary="==-=-="\r
+\r
+--==-=-=\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: inline\r
+\r
+Package: libnotmuch-dev\r
+Version: 0.18.2-1\r
+Severity: important\r
+\r
+In the API documentation for notmuch_database_close() it says:\r
+\r
+ * After notmuch_database_close has been called, calls to other\r
+ * functions on objects derived from this database may either behave\r
+ * as if the database had not been closed (e.g., if the required data\r
+ * has been cached) or may fail with a\r
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION.\r
+\r
+However, if you call notmuch_database_close() on a database and then\r
+call notmuch_database_add_message(), it doesn't fail nicely with a\r
+NOTMUCH_STATUS_XAPIAN_EXCEPTION, it segfaults.\r
+\r
+This should either be fixed so it doesn't crash, as documented, or the\r
+documentation should be changed to describe which functions are unsafe\r
+to call after notmuch_database_close().\r
+\r
+I'm attaching a small C program to reproduce the bug. It crashes with\r
+the following backtrace:\r
+\r
+(gdb) bt\r
+#0 0xb71f3f27 in Xapian::WritableDatabase::begin_transaction(bool) ()\r
+ from /usr/lib/sse2/libxapian.so.22\r
+#1 0xb779480d in notmuch_database_begin_atomic ()\r
+ from /usr/lib/i386-linux-gnu/libnotmuch.so.3\r
+#2 0xb7794fa0 in notmuch_database_add_message ()\r
+ from /usr/lib/i386-linux-gnu/libnotmuch.so.3\r
+#3 0x080488d3 in add_new_email (db=0x82b5610, \r
+ filename=0x8048b51 "/new-mail-2@example.net:2,", content=0x8048b30\r
+"hello")\r
+ at notmuchcrash.c:27\r
+#4 0x080489d7 in main () at notmuchcrash.c:52\r
+\r
+\r
+Installed version of libxapian22: 1.2.19-1+deb8u1\r
+\r
+\r
+-- System Information:\r
+Debian Release: 8.5\r
+ APT prefers stable-updates\r
+ APT policy: (500, 'stable-updates'), (500, 'stable')\r
+Architecture: i386 (i686)\r
+\r
+Kernel: Linux 3.16.0-4-686-pae (SMP w/2 CPU cores)\r
+Locale: LANG=en_GB.utf8, LC_CTYPE=en_GB.utf8 (charmap=UTF-8)\r
+Shell: /bin/sh linked to /bin/dash\r
+Init: systemd (via /run/systemd/system)\r
+\r
+Versions of packages libnotmuch-dev depends on:\r
+ii libnotmuch3 0.18.2-1\r
+\r
+libnotmuch-dev recommends no packages.\r
+\r
+libnotmuch-dev suggests no packages.\r
+\r
+-- no debconf information\r
+\r
+--==-=-=\r
+Content-Type: text/x-csrc; charset=utf-8; name=notmuchcrash.c\r
+Content-Disposition: attachment; filename=notmuchcrash.c\r
+\r
+/* Compile with:\r
+ gcc -g -std=c99 -Wall -Werror -o notmuchcrash -lnotmuch notmuchcrash.c\r
+*/\r
+\r
+#define _POSIX_C_SOURCE 200809L\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include <notmuch.h>\r
+\r
+\r
+#define DIE(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)\r
+\r
+\r
+void add_new_email(notmuch_database_t* db,\r
+ char const* filename, char const* content) {\r
+ char mail_path[64];\r
+ strcpy(mail_path, notmuch_database_get_path(db));\r
+ strcat(mail_path, filename);\r
+ FILE* mf = fopen(mail_path, "w+");\r
+ if (!mf) DIE("Failed to open mail file");\r
+ if (fwrite(content, strlen(content), 1, mf) != 1)\r
+ DIE("Failed to write mail");\r
+ if (fclose(mf)) DIE("Failed to close file");\r
+ if (notmuch_database_add_message(db, mail_path, NULL) !=\r
+ NOTMUCH_STATUS_FILE_NOT_EMAIL)\r
+ DIE("Something went wrong when adding the email");\r
+}\r
+\r
+\r
+int main() {\r
+\r
+ /* Create new database. */\r
+ char db_path[32];\r
+ strcpy(db_path, "/tmp/notmuchcrash-XXXXXX");\r
+ if (!mkdtemp(db_path)) DIE("Failed to create unique directory");\r
+ notmuch_database_t* db;\r
+ if (notmuch_database_create(db_path, &db)) DIE("Failed to create database");\r
+\r
+ /* This doesn't have to be a valid email, it will crash either way. */\r
+ char const* mail_data = "hello";\r
+\r
+ /* First, try to add a file before closing. */\r
+ add_new_email(db, "/new-mail-1@example.net:2,", mail_data);\r
+ \r
+ /* Close the database. */\r
+ notmuch_database_close(db);\r
+\r
+ /* Now try again. This will crash. */\r
+ add_new_email(db, "/new-mail-2@example.net:2,", mail_data);\r
+ \r
+ return 0;\r
+}\r
+\r
+--==-=-=\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: inline\r
+\r
+_______________________________________________\r
+notmuch mailing list\r
+notmuch@notmuchmail.org\r
+https://notmuchmail.org/mailman/listinfo/notmuch\r
+\r
+--==-=-=--\r