--- /dev/null
+Return-Path: <glasse@cs.rpi.edu>\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 BA90B429E4D\r
+ for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:13:16 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.54\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3,\r
+ RCVD_IN_SORBS_WEB=0.614] 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 7QlhXPbf2Al2 for <notmuch@notmuchmail.org>;\r
+ Wed, 15 Feb 2012 14:13:13 -0800 (PST)\r
+Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu\r
+ [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS\r
+ id 01E6D429E48 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:13:12 -0800\r
+ (PST)\r
+X-Hash:\r
+ S|a2909afab59f13fda5255d225e711418d0302a88|16748bbaf3acbf9f453a2d52848ce009\r
+X-Countries: Cameroon, United States\r
+X-SMTP-From: accepted <glasse@cs.rpi.edu> [195.24.209.20] [195.24.209.20]\r
+ (localhost) {Cameroon}\r
+DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from\r
+ :to:cc:subject:date:message-id:in-reply-to:references; s=\r
+ default; i=glasse@cs.rpi.edu; t=1329343991; x=1329948791; l=4398;\r
+ bh=5+o6UHFRfrHjxJ956HhG8NvJO+A=; b=sDhJAIuW1pOJg/8HeFT6RTo\r
+ TnXPJ1uHI2FTUhINON/hfIxlDcK9h4vzJ50owdFnT8p3z8VQwsmOl4PfJgYYeAqg\r
+ NMkSs+J7aamb6dfO5zcQnm4tDysfFYtHL0acttDy/oVtqAO/+VNfMk053iHcRms+\r
+ PiS54SvuwMiaCDH0mkt4=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc\r
+ :subject:date:message-id:in-reply-to:references; q=dns; s=\r
+ default; b=K5NQY77/tVz51x/iW5/NG/0HAjejEgiy4hGZNK8S4R2hgehhcyle4\r
+ +gqp3cvqOPK5rdPMlEdbC1ZjqsnGmulh7HL/of2oy+STcTecAfXDQjjGXXeQ8XGG\r
+ hAYt/CR2Yj/dQtriNLKJG9kDc+RfraLQq9PvoWz25++YcXVInK6S3o=\r
+X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00\r
+X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit\r
+ 15)\r
+Authentication-Results: cliffclavin.cs.rpi.edu;\r
+ DKIM=neutral (none) header.from=glasse@cs.rpi.edu;\r
+ SPF=neutral (mfrom;\r
+ Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu\r
+X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FMCjUm008878 Auth:glasse\r
+X-Virus-Scanned-By: cliffclavin.cs.rpi.edu\r
+Received: from localhost ([195.24.209.20]) (authenticated bits=0)\r
+ by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FMCjUm008878\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);\r
+ Wed, 15 Feb 2012 17:12:56 -0500 (EST)\r
+ (envelope-from glasse@cs.rpi.edu)\r
+From: Ethan Glasser-Camp <glasse@cs.rpi.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 12/13] Close files using notmuch_mailstore_close instead\r
+ of fclose\r
+Date: Wed, 15 Feb 2012 17:02:05 -0500\r
+Message-Id: <1329343326-16410-13-git-send-email-glasse@cs.rpi.edu>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>\r
+References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>\r
+X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25\r
+Cc: Ethan Glasser-Camp <ethan@betacantrips.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: Wed, 15 Feb 2012 22:13:16 -0000\r
+\r
+From: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+\r
+This requires a little bit of juggling in lib/sha1.c. Wrapper\r
+functions provide the FILE*. Instead of closing the file immediately\r
+ourselves, we let the wrapper functions close it.\r
+\r
+Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+---\r
+ lib/message-file.c | 6 ++++--\r
+ lib/sha1.c | 14 ++++++++------\r
+ mime-node.c | 4 +++-\r
+ notmuch-show.c | 8 ++++----\r
+ 4 files changed, 19 insertions(+), 13 deletions(-)\r
+\r
+diff --git a/lib/message-file.c b/lib/message-file.c\r
+index 61f4d04..51c77f9 100644\r
+--- a/lib/message-file.c\r
++++ b/lib/message-file.c\r
+@@ -34,6 +34,7 @@ typedef struct {\r
+ \r
+ struct _notmuch_message_file {\r
+ /* File object */\r
++ notmuch_mailstore_t *mailstore;\r
+ FILE *file;\r
+ \r
+ /* Header storage */\r
+@@ -86,7 +87,7 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message)\r
+ g_hash_table_destroy (message->headers);\r
+ \r
+ if (message->file)\r
+- fclose (message->file);\r
++ notmuch_mailstore_close (message->mailstore, message->file);\r
+ \r
+ return 0;\r
+ }\r
+@@ -105,6 +106,7 @@ _notmuch_message_file_open_ctx (void *ctx, notmuch_mailstore_t *mailstore,\r
+ \r
+ talloc_set_destructor (message, _notmuch_message_file_destructor);\r
+ \r
++ message->mailstore = mailstore;\r
+ message->file = notmuch_mailstore_open (mailstore, filename);\r
+ if (message->file == NULL)\r
+ goto FAIL;\r
+@@ -363,7 +365,7 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,\r
+ }\r
+ \r
+ if (message->parsing_finished) {\r
+- fclose (message->file);\r
++ notmuch_mailstore_close (message->mailstore, message->file);\r
+ message->file = NULL;\r
+ }\r
+ \r
+diff --git a/lib/sha1.c b/lib/sha1.c\r
+index ea25999..4266720 100644\r
+--- a/lib/sha1.c\r
++++ b/lib/sha1.c\r
+@@ -87,7 +87,6 @@ _notmuch_sha1_of_filep (FILE *file)\r
+ if (feof (file)) {\r
+ break;\r
+ } else if (ferror (file)) {\r
+- fclose (file);\r
+ return NULL;\r
+ }\r
+ } else {\r
+@@ -99,8 +98,6 @@ _notmuch_sha1_of_filep (FILE *file)\r
+ \r
+ result = _hex_of_sha1_digest (digest);\r
+ \r
+- fclose (file);\r
+-\r
+ return result;\r
+ }\r
+ \r
+@@ -117,9 +114,12 @@ char *\r
+ notmuch_sha1_of_file (const char *filename)\r
+ {\r
+ FILE *file;\r
++ char *ret;\r
+ \r
+ file = fopen (filename, "r");\r
+- return _notmuch_sha1_of_filep (file);\r
++ ret = _notmuch_sha1_of_filep (file);\r
++ fclose (file);\r
++ return ret;\r
+ }\r
+ \r
+ /* Create a hexadecimal string version of the SHA-1 digest of the\r
+@@ -135,7 +135,9 @@ char *\r
+ notmuch_sha1_of_message (notmuch_mailstore_t *mailstore, const char *filename)\r
+ {\r
+ FILE *file;\r
+-\r
++ char *ret;\r
+ file = notmuch_mailstore_open (mailstore, filename);\r
+- return _notmuch_sha1_of_filep (file);\r
++ ret = _notmuch_sha1_of_filep (file);\r
++ notmuch_mailstore_close (mailstore, file);\r
++ return ret;\r
+ }\r
+diff --git a/mime-node.c b/mime-node.c\r
+index 856fc3b..db37189 100644\r
+--- a/mime-node.c\r
++++ b/mime-node.c\r
+@@ -27,6 +27,7 @@\r
+ typedef struct mime_node_context {\r
+ /* Per-message resources. These are allocated internally and must\r
+ * be destroyed. */\r
++ notmuch_mailstore_t *mailstore;\r
+ FILE *file;\r
+ GMimeStream *stream;\r
+ GMimeParser *parser;\r
+@@ -54,7 +55,7 @@ _mime_node_context_free (mime_node_context_t *res)\r
+ g_object_unref (res->stream);\r
+ \r
+ if (res->file)\r
+- fclose (res->file);\r
++ notmuch_mailstore_close (res->mailstore, res->file);\r
+ \r
+ return 0;\r
+ }\r
+@@ -90,6 +91,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
+ }\r
+ talloc_set_destructor (mctx, _mime_node_context_free);\r
+ \r
++ mctx->mailstore = mailstore;\r
+ mctx->file = notmuch_mailstore_open (mailstore, filename);\r
+ if (! mctx->file) {\r
+ fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 0d2a246..2e8e4c9 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -309,7 +309,7 @@ format_message_mbox (const void *ctx,\r
+ \r
+ printf ("\n");\r
+ \r
+- fclose (file);\r
++ notmuch_mailstore_close (mailstore, file);\r
+ }\r
+ \r
+ static void\r
+@@ -966,18 +966,18 @@ do_show_single (void *ctx,\r
+ size = fread (buf, 1, sizeof (buf), file);\r
+ if (ferror (file)) {\r
+ fprintf (stderr, "Error: Read failed from %s\n", filename);\r
+- fclose (file);\r
++ notmuch_mailstore_close (mailstore, file);\r
+ return 1;\r
+ }\r
+ \r
+ if (fwrite (buf, size, 1, stdout) != 1) {\r
+ fprintf (stderr, "Error: Write failed\n");\r
+- fclose (file);\r
++ notmuch_mailstore_close (mailstore, file);\r
+ return 1;\r
+ }\r
+ }\r
+ \r
+- fclose (file);\r
++ notmuch_mailstore_close (mailstore, file);\r
+ \r
+ } else {\r
+ \r
+-- \r
+1.7.5.4\r
+\r