From: Austin Clements Date: Sun, 29 Jan 2012 05:50:10 +0000 (+1900) Subject: [PATCH 3/3] lib: Use talloc to simplify cleanup in notmuch_database_open X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=24d9d9433ef14e9dc4a4e49c63c6e83535164ff3;p=notmuch-archives.git [PATCH 3/3] lib: Use talloc to simplify cleanup in notmuch_database_open --- diff --git a/f6/e30ce51b00a3376f591a5bfbe994017df23eac b/f6/e30ce51b00a3376f591a5bfbe994017df23eac new file mode 100644 index 000000000..663c0423b --- /dev/null +++ b/f6/e30ce51b00a3376f591a5bfbe994017df23eac @@ -0,0 +1,129 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 49BD9431FBC + for ; Sat, 28 Jan 2012 21:50:16 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id LvCPwZ4rrbdA for ; + Sat, 28 Jan 2012 21:50:15 -0800 (PST) +Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU + [18.9.25.15]) + by olra.theworths.org (Postfix) with ESMTP id 88925431FB6 + for ; Sat, 28 Jan 2012 21:50:15 -0800 (PST) +X-AuditID: 1209190f-b7f8a6d000000914-be-4f24de173f27 +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP + id C4.B4.02324.71ED42F4; Sun, 29 Jan 2012 00:50:15 -0500 (EST) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0T5oErF014841; + Sun, 29 Jan 2012 00:50:14 -0500 +Received: from drake.mit.edu + (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [209.6.116.242]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0T5oCbS028025 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sun, 29 Jan 2012 00:50:13 -0500 (EST) +Received: from amthrax by drake.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1RrNeW-0007ag-C3; Sun, 29 Jan 2012 00:50:12 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 3/3] lib: Use talloc to simplify cleanup in + notmuch_database_open +Date: Sun, 29 Jan 2012 00:50:10 -0500 +Message-Id: <1327816210-29124-3-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.7.3 +In-Reply-To: <1327816210-29124-1-git-send-email-amdragon@mit.edu> +References: <1327816210-29124-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixCmqrSt+T8Xf4FYfi8X1mzOZHRg9nq26 + xRzAGMVlk5Kak1mWWqRvl8CVcbv/G2NBI2/Fw4ZHjA2MzVxdjJwcEgImElOunGKFsMUkLtxb + z9bFyMUhJLCPUaJ72WNmCGcDo8T11VtZIJz7TBJbt89hhXDmA2Xu/mYC6WcT0JDYtn85I4gt + IiAtsfPubKAiDg5mATWJP10qIGFhgUCJQy+ngpWzCKhKHP38hxnE5hVwkPh65zYbxBkKEudW + n2MHsTkFHCX+rFrBAmILAdU0NE5nnsDIv4CRYRWjbEpulW5uYmZOcWqybnFyYl5eapGuiV5u + ZoleakrpJkZw2Ejy72D8dlDpEKMAB6MSD++JpSr+QqyJZcWVuYcYJTmYlER5F9wBCvEl5adU + ZiQWZ8QXleakFh9ilOBgVhLhdZwJlONNSaysSi3Kh0lJc7AoifOqab3zExJITyxJzU5NLUgt + gsnKcHAoSfDOugvUKFiUmp5akZaZU4KQZuLgBBnOAzTcA6SGt7ggMbc4Mx0if4pRUUqcdyZI + QgAkkVGaB9cLi+tXjOJArwjzdoNU8QBTAlz3K6DBTECDI64qggwuSURISTUweiWGeh98oWLF + sjLlSglHUpn23/OTWs71POCT92DOd777Y0HatEUGm/c0xbjcPbvFxMB8vfdkrU8Hbp87fGzv + rEciTsyXnv9euGdqqtmtaTqsxVmbtX/cfy/uMeXsMo740y9WGARev2wcs6051clzU+7Zsg+X + duauUM+P2G+5nu+l8uSDl7/lPldiKc5INNRiLipOBACjnKdrxgIAAA== +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 29 Jan 2012 05:50:16 -0000 + +Previously, we manually "free"d various pointers in +notmuch_database_open. Use a local talloc context instead to simplify +cleanup and eliminate various NULL pointer initializations and +conditionals. +--- + lib/database.cc | 14 +++++--------- + 1 files changed, 5 insertions(+), 9 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 94022d7..c928d02 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -582,15 +582,15 @@ notmuch_database_t * + notmuch_database_open (const char *path, + notmuch_database_mode_t mode) + { ++ void *local = talloc_new (NULL); + notmuch_database_t *notmuch = NULL; +- char *notmuch_path = NULL, *xapian_path = NULL; ++ char *notmuch_path, *xapian_path; + struct stat st; + int err; + unsigned int i, version; + static int initialized = 0; + +- if (asprintf (¬much_path, "%s/%s", path, ".notmuch") == -1) { +- notmuch_path = NULL; ++ if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) { + fprintf (stderr, "Out of memory\n"); + goto DONE; + } +@@ -602,8 +602,7 @@ notmuch_database_open (const char *path, + goto DONE; + } + +- if (asprintf (&xapian_path, "%s/%s", notmuch_path, "xapian") == -1) { +- xapian_path = NULL; ++ if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) { + fprintf (stderr, "Out of memory\n"); + goto DONE; + } +@@ -708,10 +707,7 @@ notmuch_database_open (const char *path, + } + + DONE: +- if (notmuch_path) +- free (notmuch_path); +- if (xapian_path) +- free (xapian_path); ++ talloc_free (local); + + return notmuch; + } +-- +1.7.7.3 +