From 1af1e0485c3a5340010062aa728165473b01facc Mon Sep 17 00:00:00 2001 From: Dmitry Kurochkin Date: Tue, 7 Feb 2012 14:10:52 +0400 Subject: [PATCH] Re: [PATCH] Free the results of scandir() --- 54/cf926974d7634ed3a18f0c3e267c601993c040 | 135 ++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 54/cf926974d7634ed3a18f0c3e267c601993c040 diff --git a/54/cf926974d7634ed3a18f0c3e267c601993c040 b/54/cf926974d7634ed3a18f0c3e267c601993c040 new file mode 100644 index 000000000..247b04791 --- /dev/null +++ b/54/cf926974d7634ed3a18f0c3e267c601993c040 @@ -0,0 +1,135 @@ +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 17B67431FB6 + for ; Tue, 7 Feb 2012 02:12:11 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, 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 fcB5ddDOzYAl for ; + Tue, 7 Feb 2012 02:12:10 -0800 (PST) +Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com + [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 455DB431FAE + for ; Tue, 7 Feb 2012 02:12:10 -0800 (PST) +Received: by bke11 with SMTP id 11so6307784bke.26 + for ; Tue, 07 Feb 2012 02:12:08 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; + h=from:to:cc:subject:in-reply-to:references:user-agent:date + :message-id:mime-version:content-type; + bh=IjOAF5+bAiHOlY5uM6/2HoOgp7zuPam7qRQxCcy2UCE=; + b=mW5udbxRZBjo9WZg3VxaKMd+bWe3OETrIQ39qdSCOI2h8ThJTovwajW054meDdFa1f + MmZzRtMe9zJ4qfnaksQPLIaN3KG1ytHymNoWdO5vfuo6MOCTQj2Ruz4NS1o8jQN9s4Nh + K5rHWIpXzts2u0BVLg1Zp3IA6L7owvKySR98Y= +Received: by 10.204.157.17 with SMTP id z17mr9959543bkw.37.1328609528838; + Tue, 07 Feb 2012 02:12:08 -0800 (PST) +Received: from localhost ([91.144.186.21]) + by mx.google.com with ESMTPS id w15sm13223841bku.0.2012.02.07.02.12.07 + (version=TLSv1/SSLv3 cipher=OTHER); + Tue, 07 Feb 2012 02:12:08 -0800 (PST) +From: Dmitry Kurochkin +To: Ethan Glasser-Camp , notmuch@notmuchmail.org +Subject: Re: [PATCH] Free the results of scandir() +In-Reply-To: <1328609103-7870-1-git-send-email-glasse@cs.rpi.edu> +References: <1328609103-7870-1-git-send-email-glasse@cs.rpi.edu> +User-Agent: Notmuch/0.11+139~gd9b7cab (http://notmuchmail.org) Emacs/23.3.1 + (x86_64-pc-linux-gnu) +Date: Tue, 07 Feb 2012 14:10:52 +0400 +Message-ID: <87vcnjx8b7.fsf@gmail.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Cc: Ethan Glasser-Camp +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: Tue, 07 Feb 2012 10:12:11 -0000 + +On Tue, 7 Feb 2012 05:05:03 -0500, Ethan Glasser-Camp wrote: +> From: Ethan Glasser-Camp +> +> scandir() returns "strings allocated via malloc(3)" which are then +> "collected in array namelist which is allocated via +> malloc(3)". Currently we just free the array namelist. Instead, free +> all the entries of namelist, and then free namelist. +> +> entry only points to elements of namelist, so we don't free it +> separately. +> --- +> +> v3: I'm still learning the house style. Thanks Dmitry. +> + +Looks good. + +Please use --subject-prefix='PATCH vN' parameter when sending new +versions of patches. Also, sending new versions as replies to the first +email in the original thread makes it easier to track. + +Regards, + Dmitry + +> notmuch-new.c | 16 ++++++++++------ +> 1 files changed, 10 insertions(+), 6 deletions(-) +> +> diff --git a/notmuch-new.c b/notmuch-new.c +> index a569a54..8dbebb3 100644 +> --- a/notmuch-new.c +> +++ b/notmuch-new.c +> @@ -559,12 +559,14 @@ add_files_recursive (notmuch_database_t *notmuch, +> DONE: +> if (next) +> talloc_free (next); +> - if (entry) +> - free (entry); +> if (dir) +> closedir (dir); +> - if (fs_entries) +> + if (fs_entries) { +> + for (i = 0; i < num_fs_entries; i++) +> + free (fs_entries[i]); +> + +> free (fs_entries); +> + } +> if (db_subdirs) +> notmuch_filenames_destroy (db_subdirs); +> if (db_files) +> @@ -704,10 +706,12 @@ count_files (const char *path, int *count) +> } +> +> DONE: +> - if (entry) +> - free (entry); +> - if (fs_entries) +> + if (fs_entries) { +> + for (i = 0; i < num_fs_entries; i++) +> + free (fs_entries[i]); +> + +> free (fs_entries); +> + } +> } +> +> static void +> -- +> 1.7.5.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2