[PATCH 2/5] cppcheck: close files during shutdown

Subject: [PATCH 2/5] cppcheck: close files during shutdown

Date: Sat, 26 Aug 2017 11:41:38 -0300

To: notmuch@notmuchmail.org, notmuch@freelists.org

Cc: David Bremner

From: David Bremner


Fix the following cppcheck errors:

    notmuch-count.c:207: error: Resource leak: input
    notmuch-tag.c:238: error: Resource leak: input

We know that the program is shutting down here, but it does no harm to
clean up a bit.
---
 notmuch-count.c | 2 ++
 notmuch-tag.c   | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/notmuch-count.c b/notmuch-count.c
index 50b0c193..97281374 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -204,6 +204,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
 
     if (batch && opt_index != argc) {
 	fprintf (stderr, "--batch and query string are not compatible\n");
+	if (input)
+	    fclose (input);
 	return EXIT_FAILURE;
     }
 
diff --git a/notmuch-tag.c b/notmuch-tag.c
index 9c03754d..130de634 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -235,6 +235,8 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
     if (batch) {
 	if (opt_index != argc) {
 	    fprintf (stderr, "Can't specify both cmdline and stdin!\n");
+	    if (input)
+		fclose (input);
 	    return EXIT_FAILURE;
 	}
     } else {
-- 
2.14.1



Thread: