[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240903080121.5294-1-zhangjiao2@cmss.chinamobile.com>
Date: Tue, 3 Sep 2024 16:01:21 +0800
From: zhangjiao2 <zhangjiao2@...s.chinamobile.com>
To: wbg@...nel.org
Cc: linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org,
zhang jiao <zhangjiao2@...s.chinamobile.com>
Subject: [PATCH] tools/counter: close fd when exit
From: zhang jiao <zhangjiao2@...s.chinamobile.com>
close fd when exit the program
Signed-off-by: zhang jiao <zhangjiao2@...s.chinamobile.com>
---
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) {
fprintf(stderr, "Error adding watches[%d]: %s\n", i,
strerror(errno));
+ close(fd);
return 1;
}
}
ret = ioctl(fd, COUNTER_ENABLE_EVENTS_IOCTL);
if (ret == -1) {
perror("Error enabling events");
+ close(fd);
return 1;
}
@@ -70,11 +72,13 @@ int main(void)
ret = read(fd, event_data, sizeof(event_data));
if (ret == -1) {
perror("Failed to read event data");
+ close(fd);
return 1;
}
if (ret != sizeof(event_data)) {
fprintf(stderr, "Failed to read event data\n");
+ close(fd);
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