Fix fd leaks
When you open a file, you should remember to close it.
bug:2639464
Change-Id: I90d25dba2a262b620373270832eb3189616c720d
diff --git a/TetherController.cpp b/TetherController.cpp
index 30ff165..2fc2138 100644
--- a/TetherController.cpp
+++ b/TetherController.cpp
@@ -61,6 +61,7 @@
if (write(fd, (enable ? "1" : "0"), 1) != 1) {
LOGE("Failed to write ip_forward (%s)", strerror(errno));
+ close(fd);
return -1;
}
close(fd);
@@ -78,11 +79,11 @@
char enabled;
if (read(fd, &enabled, 1) != 1) {
LOGE("Failed to read ip_forward (%s)", strerror(errno));
+ close(fd);
return -1;
}
close(fd);
-
return (enabled == '1' ? true : false);
}