From 11aa4a386634d834b27c13d0cac3cfd2d804905b Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fischer@muhq.space>
Date: Wed, 21 Jul 2021 11:24:06 +0200
Subject: [PATCH] [fsearch] close files after searching them

---
 apps/fsearch/fsearch.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/apps/fsearch/fsearch.cpp b/apps/fsearch/fsearch.cpp
index 09f479d1..118253b0 100644
--- a/apps/fsearch/fsearch.cpp
+++ b/apps/fsearch/fsearch.cpp
@@ -38,7 +38,7 @@ void search(const std::string& path) {
 	while (bytes_read > 0) {
 		if (memmem(&buf[0], bytes_read, needle, needle_len)) {
 			printf("%s\n", path.c_str());
-			return;
+			goto out;
 		}
 
 		bytes_searched += bytes_read;
@@ -48,6 +48,9 @@ void search(const std::string& path) {
 	if (bytes_read < 0) {
 		DIE_MSG_ERRNO("read failed");
 	}
+
+out:
+	emper::io::closeAndForget(fd);
 }
 
 void walk_dir() {
-- 
GitLab