1 Return-Path: <djcb@djcbsoftware.nl>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id B8302431FBF
\r
6 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 08:16:48 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id vyvxzL9IvHr5 for <notmuch@notmuchmail.org>;
\r
11 Tue, 24 Nov 2009 08:16:46 -0800 (PST)
\r
12 Received: from gw03.mail.saunalahti.fi (gw03.mail.saunalahti.fi
\r
14 by olra.theworths.org (Postfix) with ESMTP id B422E431FAE
\r
15 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 08:16:45 -0800 (PST)
\r
16 Received: from djcbsoftware.nl (a88-112-254-208.elisa-laajakaista.fi
\r
18 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by gw03.mail.saunalahti.fi (Postfix) with ESMTP id 5443A216682
\r
21 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 18:16:39 +0200 (EET)
\r
22 Received: from cthulhu.mindcrime.djcbsoftware.nl (localhost [127.0.0.1])
\r
23 by djcbsoftware.nl (Postfix) with ESMTP id 73FF039C53B
\r
24 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 16:22:02 +0200 (EET)
\r
25 Date: Tue, 24 Nov 2009 16:22:02 +0200
\r
26 Message-ID: <873a4480l1.wl%djcb@djcbsoftware.nl>
\r
27 From: Dirk-Jan C. Binnema <djcb.bulk@gmail.com>
\r
28 To: "notmuch@notmuchmail org" <notmuch@notmuchmail.org>
\r
29 Mail-Reply-To: djcb@djcbsoftware.nl
\r
30 User-Agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/23.1 Mule/6.0
\r
32 Organization: DJCBSoftware
\r
33 MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka")
\r
34 Content-Type: text/plain; charset=US-ASCII
\r
35 Subject: [notmuch] [PATCH] notmuch-count: make sure all created items are
\r
36 freed, even in error paths
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.12
\r
40 Reply-To: djcb@djcbsoftware.nl
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Tue, 24 Nov 2009 16:16:48 -0000
\r
53 Another minor patch, fixing a couple of resource leaks in error paths.
\r
56 notmuch-count.c | 52 ++++++++++++++++++++++++++++++++++++----------------
\r
57 1 files changed, 36 insertions(+), 16 deletions(-)
\r
59 diff --git a/notmuch-count.c b/notmuch-count.c
\r
60 index 77aa433..b5808f5 100644
\r
61 --- a/notmuch-count.c
\r
62 +++ b/notmuch-count.c
\r
63 @@ -28,7 +28,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
64 notmuch_database_t *notmuch;
\r
65 notmuch_query_t *query;
\r
72 int i, first = 0, max_threads = -1;
\r
73 @@ -76,35 +77,54 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
82 config = notmuch_config_open (ctx, NULL, NULL);
\r
83 - if (config == NULL)
\r
86 - notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
87 - NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
88 - if (notmuch == NULL)
\r
91 + if (config == NULL) {
\r
96 query_str = query_string_from_args (ctx, argc, argv);
\r
97 if (query_str == NULL) {
\r
98 fprintf (stderr, "Out of memory.\n");
\r
103 if (*query_str == '\0') {
\r
104 fprintf (stderr, "Error: notmuch count requires at least one count term.\n");
\r
111 + notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
112 + NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
113 + if (notmuch == NULL) {
\r
114 + fprintf (stderr, "Failed to open database at %s\n",
\r
115 + notmuch_config_get_database_path (config));
\r
120 query = notmuch_query_create (notmuch, query_str);
\r
121 if (query == NULL) {
\r
122 fprintf (stderr, "Out of memory\n");
\r
128 printf ("%u\n", notmuch_query_count_messages(query));
\r
132 + talloc_free (query_str);
\r
133 + notmuch_config_close (config);
\r
134 notmuch_query_destroy (query);
\r
135 - notmuch_database_close (notmuch);
\r
138 + if (notmuch) /* _close does not allow NULL */
\r
139 + notmuch_database_close (notmuch);
\r