[PATCH] cli: add a tool for starting new message in the emacs ui
[notmuch-archives.git] / fe / a17d8bd70ef9502fba6baff5879da432b65a1b
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
13         [195.197.172.111])\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
17         [88.112.254.208])\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
31         (HANACHIRUSATO)\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
39 Precedence: list\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
51 \r
52 \r
53 Another minor patch, fixing a couple of resource leaks in error paths.\r
54 \r
55 ---\r
56  notmuch-count.c |   52 ++++++++++++++++++++++++++++++++++++----------------\r
57  1 files changed, 36 insertions(+), 16 deletions(-)\r
58 \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
66      char *query_str;\r
67 -    int i;\r
68 +    int i, retval;\r
69 +    \r
70  #if 0\r
71      char *opt, *end;\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
74      argc -= i;\r
75      argv += i;\r
76  \r
77 +    config    = NULL;\r
78 +    query_str = NULL;\r
79 +    notmuch   = NULL;\r
80 +    query     = NULL;\r
81 +    \r
82      config = notmuch_config_open (ctx, NULL, NULL);\r
83 -    if (config == NULL)\r
84 -       return 1;\r
85 -\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
89 -       return 1;\r
90 -\r
91 +    if (config == NULL) {\r
92 +       retval = 1;\r
93 +       goto out;\r
94 +    }\r
95 +    \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
99 -       return 1;\r
100 +       retval = 1;\r
101 +       goto out;\r
102      }\r
103      if (*query_str == '\0') {\r
104         fprintf (stderr, "Error: notmuch count requires at least one count term.\n");\r
105 -       return 1;\r
106 +       retval = 1;\r
107 +       goto out;\r
108      }\r
109 -\r
110 +    \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
116 +       retval = 1;\r
117 +       goto out;\r
118 +    }\r
119 +    \r
120      query = notmuch_query_create (notmuch, query_str);\r
121      if (query == NULL) {\r
122         fprintf (stderr, "Out of memory\n");\r
123 -       return 1;\r
124 +       retval = 1;\r
125 +       goto out;\r
126      }\r
127  \r
128      printf ("%u\n", notmuch_query_count_messages(query));\r
129 +    retval = 0;\r
130  \r
131 +out:\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
136 -\r
137 -    return 0;\r
138 +    if (notmuch) /* _close does not allow NULL */\r
139 +       notmuch_database_close (notmuch);\r
140 +    \r
141 +    return retval;\r
142  }\r
143 -- \r
144 1.6.3.3\r
145 \r