From: Ethan Glasser-Camp <glasse@cs.rpi.edu>
To: notmuch@notmuchmail.org
Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
Subject: [PATCH] Free the results of scandir()
Date: Tue, 7 Feb 2012 05:05:03 -0500 [thread overview]
Message-ID: <1328609103-7870-1-git-send-email-glasse@cs.rpi.edu> (raw)
From: Ethan Glasser-Camp <ethan@betacantrips.com>
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.
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
next reply other threads:[~2012-02-07 10:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-07 10:05 Ethan Glasser-Camp [this message]
2012-02-07 10:10 ` [PATCH] Free the results of scandir() Dmitry Kurochkin
2012-02-07 10:13 ` Ethan Glasser-Camp
2012-02-07 10:30 ` Tomi Ollila
2012-02-15 3:47 ` David Bremner
-- strict thread matches above, loose matches on Subject: below --
2012-02-06 22:02 Ethan Glasser-Camp
2012-02-06 22:21 ` Jani Nikula
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328609103-7870-1-git-send-email-glasse@cs.rpi.edu \
--to=glasse@cs.rpi.edu \
--cc=ethan@betacantrips.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).