diff mbox series

[iproute2-next] lib: utils: close file handle on error

Message ID 20241031121411.20556-1-kirjanov@gmail.com (mailing list archive)
State New
Delegated to: David Ahern
Headers show
Series [iproute2-next] lib: utils: close file handle on error | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Denis Kirjanov Oct. 31, 2024, 12:14 p.m. UTC
reap_prop() doesn't close the file descriptor
on some errors, fix it.

Signed-off-by: Denis Kirjanov <kirjanov@gmail.com>
---
 lib/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/utils.c b/lib/utils.c
index 66713251..aea4e8b7 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -73,7 +73,6 @@  int read_prop(const char *dev, char *prop, long *value)
 
 	if (!fgets(buf, sizeof(buf), fp)) {
 		fprintf(stderr, "property \"%s\" in file %s is currently unknown\n", prop, fname);
-		fclose(fp);
 		goto out;
 	}
 
@@ -98,6 +97,7 @@  int read_prop(const char *dev, char *prop, long *value)
 	*value = result;
 	return 0;
 out:
+	fclose(fp);
 	fprintf(stderr, "Failed to parse %s\n", fname);
 	return -1;
 }