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 2E138431FAF for ; Sun, 16 Dec 2012 14:41:18 -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 JzGigM5Zzgo6 for ; Sun, 16 Dec 2012 14:41:17 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 40723431FAE for ; Sun, 16 Dec 2012 14:41:17 -0800 (PST) Received: by mail-lb0-f181.google.com with SMTP id ge1so4083048lbb.26 for ; Sun, 16 Dec 2012 14:41:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type:x-gm-message-state; bh=cqaFOzs62Te1J0RpDPkl6NQStKZTCgly1GYCqm/9AMQ=; b=HJETT2P+6f+L0VKblXINRJyn7Yrett/KjUYEYZUZ0qp/Npx8wn/B4l8CnQsHD7PySP bKw/GhEyIo/Uyzi38eRaESPPW58FgixubO/ViPufskPNjRJY64OoWvtKuFtq1KrsUFIB w3kSXDRuBGXQ3A7F71EHMQbZMFkkl9Lhc8TjJdLqUhGq3hDzcPsUiN7cQq5ti4K3EC3C yMXoOBTwGEmOCzcmDo+w3gODVfToIq5RwQAlLRwR/Aqa4QOP/TDa5YvG6D8rcNNkt7TD KY4YI9KPfAqfAwHZHMmp37iii4EvEXCVFMmgszJoRNUUDz9EyoZWaDySgUtOKK0WzLRg oeiw== Received: by 10.112.83.100 with SMTP id p4mr5048275lby.96.1355697675705; Sun, 16 Dec 2012 14:41:15 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id ne2sm4136684lab.10.2012.12.16.14.41.13 (version=SSLv3 cipher=OTHER); Sun, 16 Dec 2012 14:41:14 -0800 (PST) From: Jani Nikula To: david@tethera.net, notmuch@notmuchmail.org Subject: Re: [PATCH 3/3] notmuch-restore: allocate a temporary talloc context for each line parsed. In-Reply-To: <1355688997-19164-4-git-send-email-david@tethera.net> References: <1355688997-19164-1-git-send-email-david@tethera.net> <1355688997-19164-4-git-send-email-david@tethera.net> User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Mon, 17 Dec 2012 00:41:12 +0200 Message-ID: <87ip81pqlz.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQmY0f2V6oBOtXX0PPWxxSqtiNu9/NXE8l70UadLGl939ySkZwfwbeIzsj/OC9XZ7gYAux8Z Cc: David Bremner 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, 16 Dec 2012 22:41:18 -0000 On Sun, 16 Dec 2012, david@tethera.net wrote: > From: David Bremner > > This lets the high level code in notmuch restore be ignorant about > what the lower level code is doing as far as allocating memory. > --- > notmuch-restore.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/notmuch-restore.c b/notmuch-restore.c > index 4b76d83..52e7ecb 100644 > --- a/notmuch-restore.c > +++ b/notmuch-restore.c > @@ -122,6 +122,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) > char *input_file_name = NULL; > FILE *input = stdin; > char *line = NULL; > + void *line_ctx = NULL; > size_t line_size; > ssize_t line_len; > > @@ -205,10 +206,11 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) > do { > char *query_string; This patch only works on top of the batch tagging series, because there's still one continue statement in the "id:" prefix check. But you could make it work for both, *and* keep the slightly more intuitive ret checking order if you did (yes, the slightly counter-intuitive): if (line_ctxt != NULL) talloc_free (line_ctx); right here, and... > + line_ctx = talloc_new (ctx); > if (input_format == DUMP_FORMAT_SUP) { > - ret = parse_sup_line (ctx, line, &query_string, tag_ops); > + ret = parse_sup_line (line_ctx, line, &query_string, tag_ops); > } else { > - ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS, > + ret = parse_tag_line (line_ctx, line, TAG_FLAG_BE_GENEROUS, > &query_string, tag_ops); > > if (ret == 0) { > @@ -238,8 +240,14 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) > break; > } > > + talloc_free (line_ctx); > + /* setting to NULL is important to avoid a double free */ > + line_ctx = NULL; ...removed the above lines here. Otherwise I think you'll need a temporary goto until the batch tagging series. (I'm fine with that too.) Overall the series LGTM, and I like how this dodges the query_string alloc/free problem altogether. BR, Jani. > } while ((line_len = getline (&line, &line_size, input)) != -1); > > + if (line_ctx != NULL) > + talloc_free (line_ctx); > + > if (input_format == DUMP_FORMAT_SUP) > regfree (®ex); > > -- > 1.7.10.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch