[PATCH v2] Free the results of scandir()
authorEthan Glasser-Camp <glasse@cs.rpi.edu>
Tue, 7 Feb 2012 06:50:05 +0000 (01:50 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:14 +0000 (09:44 -0800)
14/632972f681aaaf0e13d54a4753218d07fac754 [new file with mode: 0644]

diff --git a/14/632972f681aaaf0e13d54a4753218d07fac754 b/14/632972f681aaaf0e13d54a4753218d07fac754
new file mode 100644 (file)
index 0000000..71de714
--- /dev/null
@@ -0,0 +1,132 @@
+Return-Path: <glasse@cs.rpi.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E5820431FAF\r
+       for <notmuch@notmuchmail.org>; Mon,  6 Feb 2012 22:50:43 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.54\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3,\r
+       RCVD_IN_SORBS_WEB=0.614] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id aJHR4KKIUsKc for <notmuch@notmuchmail.org>;\r
+       Mon,  6 Feb 2012 22:50:43 -0800 (PST)\r
+Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu\r
+ [128.113.126.25])     (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)       by olra.theworths.org (Postfix) with ESMTPS\r
+ id 3E91F431FAE        for <notmuch@notmuchmail.org>; Mon,  6 Feb 2012 22:50:43 -0800\r
+ (PST)\r
+X-Hash:\r
+ S|40e4c517ca0459386989b82fa84cfcb00c964d05|ab058044c63300b1ad8418f36616e81f\r
+X-Countries: Cameroon, United States\r
+X-SMTP-From: accepted <glasse@cs.rpi.edu> [195.24.209.22] [195.24.209.22]\r
+       (localhost) {Cameroon}\r
+DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from\r
+       :to:cc:subject:date:message-id; s=default; i=glasse@cs.rpi.edu;\r
+       t=1328597441; x=1329202241; l=1324; bh=RQpuYYAQVZCaa6oTlvwssFG3\r
+       WrI=; b=P11A6fwMJ1pOKwgqk1xINRibAzSKZFUrxxUDmO3pOZMcyYfeqTwJmLaJ\r
+       oXRWkiO55uF7vhTyh6eqd5MpmonyhmApUjYbCo+WFEXfP8BnZS8xsm+pwqXM0wpR\r
+       SiFRCtdg+UIQERbwtX++EpdHwr979EKLAvkWGs9RmZlWWRmvtQw=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc\r
+       :subject:date:message-id; q=dns; s=default; b=QXz70/Sq93rAKju6LX\r
+       GjRH2Uq9PJek+G3djd1xqIsHL6aPwBzWSbVm9lSyv17rjyPmf7tKowyBoCRGN+BK\r
+       96RNLpasN7TPbRGF4lYDudkUU7jfChzP7QAUAQjxdGVm6fvuPwebDOYJBaqLtpmT\r
+       18QvSLtg9bKmINgdQIO/7S5fk=\r
+X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00\r
+X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit\r
+       15)\r
+Authentication-Results: cliffclavin.cs.rpi.edu;\r
+       DKIM=neutral (none) header.from=glasse@cs.rpi.edu;\r
+       SPF=neutral (mfrom;\r
+       Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu\r
+X-Auth-Passed: cliffclavin.cs.rpi.edu:q176oJxj073383 Auth:glasse\r
+X-Virus-Scanned-By: cliffclavin.cs.rpi.edu\r
+Received: from localhost ([195.24.209.22]) (authenticated bits=0)\r
+       by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q176oJxj073383\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);\r
+       Tue, 7 Feb 2012 01:50:34 -0500 (EST)\r
+       (envelope-from glasse@cs.rpi.edu)\r
+From: Ethan Glasser-Camp <glasse@cs.rpi.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2] Free the results of scandir()\r
+Date: Tue,  7 Feb 2012 01:50:05 -0500\r
+Message-Id: <1328597405-6437-1-git-send-email-glasse@cs.rpi.edu>\r
+X-Mailer: git-send-email 1.7.5.4\r
+X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25\r
+Cc: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 07 Feb 2012 06:50:44 -0000\r
+\r
+From: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+\r
+scandir() returns "strings allocated via malloc(3)" which are then\r
+"collected in array namelist which is allocated via\r
+malloc(3)". Currently we just free the array namelist. Instead, free\r
+all the entries of namelist, and then free namelist.\r
+\r
+entry only points to elements of namelist, so we don't free it\r
+separately.\r
+---\r
+\r
+Fixes the other use of scandir in count_files. Thanks, Jani.\r
+\r
+ notmuch-new.c |   16 ++++++++++------\r
+ 1 files changed, 10 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index a569a54..e62560b 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -559,12 +559,14 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+   DONE:\r
+     if (next)\r
+       talloc_free (next);\r
+-    if (entry)\r
+-      free (entry);\r
+     if (dir)\r
+       closedir (dir);\r
+-    if (fs_entries)\r
++    if (fs_entries){\r
++      for (i = 0; i < num_fs_entries; i++){\r
++          free (fs_entries[i]);\r
++      }\r
+       free (fs_entries);\r
++    }\r
+     if (db_subdirs)\r
+       notmuch_filenames_destroy (db_subdirs);\r
+     if (db_files)\r
+@@ -704,10 +706,12 @@ count_files (const char *path, int *count)\r
+     }\r
+ \r
+   DONE:\r
+-    if (entry)\r
+-      free (entry);\r
+-    if (fs_entries)\r
++    if (fs_entries){\r
++      for (i = 0; i < num_fs_entries; i++){\r
++          free (fs_entries[i]);\r
++      }\r
+         free (fs_entries);\r
++    }\r
+ }\r
+ \r
+ static void\r
+-- \r
+1.7.5.4\r
+\r