1 Return-Path: <amthrax@drake.mit.edu>
\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 49BD9431FBC
\r
6 for <notmuch@notmuchmail.org>; Sat, 28 Jan 2012 21:50:16 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id LvCPwZ4rrbdA for <notmuch@notmuchmail.org>;
\r
16 Sat, 28 Jan 2012 21:50:15 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 88925431FB6
\r
20 for <notmuch@notmuchmail.org>; Sat, 28 Jan 2012 21:50:15 -0800 (PST)
\r
21 X-AuditID: 1209190f-b7f8a6d000000914-be-4f24de173f27
\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])
\r
23 by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id C4.B4.02324.71ED42F4; Sun, 29 Jan 2012 00:50:15 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0T5oErF014841;
\r
27 Sun, 29 Jan 2012 00:50:14 -0500
\r
28 Received: from drake.mit.edu
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0T5oCbS028025
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Sun, 29 Jan 2012 00:50:13 -0500 (EST)
\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
36 (envelope-from <amthrax@drake.mit.edu>)
\r
37 id 1RrNeW-0007ag-C3; Sun, 29 Jan 2012 00:50:12 -0500
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 3/3] lib: Use talloc to simplify cleanup in
\r
41 notmuch_database_open
\r
42 Date: Sun, 29 Jan 2012 00:50:10 -0500
\r
43 Message-Id: <1327816210-29124-3-git-send-email-amdragon@mit.edu>
\r
44 X-Mailer: git-send-email 1.7.7.3
\r
45 In-Reply-To: <1327816210-29124-1-git-send-email-amdragon@mit.edu>
\r
46 References: <1327816210-29124-1-git-send-email-amdragon@mit.edu>
\r
47 X-Brightmail-Tracker:
\r
48 H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixCmqrSt+T8Xf4FYfi8X1mzOZHRg9nq26
\r
49 xRzAGMVlk5Kak1mWWqRvl8CVcbv/G2NBI2/Fw4ZHjA2MzVxdjJwcEgImElOunGKFsMUkLtxb
\r
50 z9bFyMUhJLCPUaJ72WNmCGcDo8T11VtZIJz7TBJbt89hhXDmA2Xu/mYC6WcT0JDYtn85I4gt
\r
51 IiAtsfPubKAiDg5mATWJP10qIGFhgUCJQy+ngpWzCKhKHP38hxnE5hVwkPh65zYbxBkKEudW
\r
52 n2MHsTkFHCX+rFrBAmILAdU0NE5nnsDIv4CRYRWjbEpulW5uYmZOcWqybnFyYl5eapGuiV5u
\r
53 ZoleakrpJkZw2Ejy72D8dlDpEKMAB6MSD++JpSr+QqyJZcWVuYcYJTmYlER5F9wBCvEl5adU
\r
54 ZiQWZ8QXleakFh9ilOBgVhLhdZwJlONNSaysSi3Kh0lJc7AoifOqab3zExJITyxJzU5NLUgt
\r
55 gsnKcHAoSfDOugvUKFiUmp5akZaZU4KQZuLgBBnOAzTcA6SGt7ggMbc4Mx0if4pRUUqcdyZI
\r
56 QgAkkVGaB9cLi+tXjOJArwjzdoNU8QBTAlz3K6DBTECDI64qggwuSURISTUweiWGeh98oWLF
\r
57 sjLlSglHUpn23/OTWs71POCT92DOd777Y0HatEUGm/c0xbjcPbvFxMB8vfdkrU8Hbp87fGzv
\r
58 rEciTsyXnv9euGdqqtmtaTqsxVmbtX/cfy/uMeXsMo740y9WGARev2wcs6051clzU+7Zsg+X
\r
59 duauUM+P2G+5nu+l8uSDl7/lPldiKc5INNRiLipOBACjnKdrxgIAAA==
\r
60 X-BeenThere: notmuch@notmuchmail.org
\r
61 X-Mailman-Version: 2.1.13
\r
63 List-Id: "Use and development of the notmuch mail system."
\r
64 <notmuch.notmuchmail.org>
\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
68 List-Post: <mailto:notmuch@notmuchmail.org>
\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
72 X-List-Received-Date: Sun, 29 Jan 2012 05:50:16 -0000
\r
74 Previously, we manually "free"d various pointers in
\r
75 notmuch_database_open. Use a local talloc context instead to simplify
\r
76 cleanup and eliminate various NULL pointer initializations and
\r
79 lib/database.cc | 14 +++++---------
\r
80 1 files changed, 5 insertions(+), 9 deletions(-)
\r
82 diff --git a/lib/database.cc b/lib/database.cc
\r
83 index 94022d7..c928d02 100644
\r
84 --- a/lib/database.cc
\r
85 +++ b/lib/database.cc
\r
86 @@ -582,15 +582,15 @@ notmuch_database_t *
\r
87 notmuch_database_open (const char *path,
\r
88 notmuch_database_mode_t mode)
\r
90 + void *local = talloc_new (NULL);
\r
91 notmuch_database_t *notmuch = NULL;
\r
92 - char *notmuch_path = NULL, *xapian_path = NULL;
\r
93 + char *notmuch_path, *xapian_path;
\r
96 unsigned int i, version;
\r
97 static int initialized = 0;
\r
99 - if (asprintf (¬much_path, "%s/%s", path, ".notmuch") == -1) {
\r
100 - notmuch_path = NULL;
\r
101 + if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {
\r
102 fprintf (stderr, "Out of memory\n");
\r
105 @@ -602,8 +602,7 @@ notmuch_database_open (const char *path,
\r
109 - if (asprintf (&xapian_path, "%s/%s", notmuch_path, "xapian") == -1) {
\r
110 - xapian_path = NULL;
\r
111 + if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {
\r
112 fprintf (stderr, "Out of memory\n");
\r
115 @@ -708,10 +707,7 @@ notmuch_database_open (const char *path,
\r
119 - if (notmuch_path)
\r
120 - free (notmuch_path);
\r
122 - free (xapian_path);
\r
123 + talloc_free (local);
\r