lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240904014253.2435-1-zhangjiao2@cmss.chinamobile.com>
Date: Wed,  4 Sep 2024 09:42:53 +0800
From: zhangjiao2 <zhangjiao2@...s.chinamobile.com>
To: andy.shevchenko@...il.com
Cc: wbg@...nel.org,
	linux-iio@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	zhang jiao <zhangjiao2@...s.chinamobile.com>
Subject: [PATCH v2] tools/counter: Close fd when exit

From: zhang jiao <zhangjiao2@...s.chinamobile.com>

Since fd is not used in the messaging it's better to 
close it before printing anything. Ditto for other cases.

Signed-off-by: zhang jiao <zhangjiao2@...s.chinamobile.com>
---
v1->v2:
	Close fd before fprintf.

 tools/counter/counter_example.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/counter/counter_example.c b/tools/counter/counter_example.c
index be55287b950f..37569208c235 100644
--- a/tools/counter/counter_example.c
+++ b/tools/counter/counter_example.c
@@ -57,12 +57,14 @@ int main(void)
 		if (ret == -1) {
+			close(fd);
 			fprintf(stderr, "Error adding watches[%d]: %s\n", i,
 				strerror(errno));
 			return 1;
 		}
 	}
 	ret = ioctl(fd, COUNTER_ENABLE_EVENTS_IOCTL);
 	if (ret == -1) {
+		close(fd);
 		perror("Error enabling events");
 		return 1;
 	}
 
@@ -70,11 +72,13 @@ int main(void)
 		ret = read(fd, event_data, sizeof(event_data));
 		if (ret == -1) {
+			close(fd);
 			perror("Failed to read event data");
 			return 1;
 		}
 
 		if (ret != sizeof(event_data)) {
+			close(fd);
 			fprintf(stderr, "Failed to read event data\n");
 			return -EIO;
 		}
 
@@ -88,5 +92,6 @@ int main(void)
 		       strerror(event_data[1].status));
 	}
 
+	close(fd);
 	return 0;
 }
-- 
2.33.0




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ