Fix a few fd leaks.
There were a few fd/FILE* leaks in system.c.
Bug: None
Test: Unit tests pass.
Change-Id: I2f793c7b7dd27ab91e69b9e69ba9c5266f966ef9
diff --git a/system.c b/system.c
index 10e1499..40f0883 100644
--- a/system.c
+++ b/system.c
@@ -133,11 +133,13 @@
written = write(fd, content, len);
if (written < 0) {
pwarn("failed to write '%s'", filename);
+ close(fd);
return -errno;
}
if ((size_t)written < len) {
warn("failed to write %zu bytes to '%s'", len, filename);
+ close(fd);
return -1;
}
close(fd);
@@ -204,6 +206,7 @@
strcpy(ifr.ifr_name, ifname);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
pwarn("ioctl(SIOCGIFFLAGS) failed");
+ close(sock);
return -1;
}
@@ -211,6 +214,7 @@
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
pwarn("ioctl(SIOCSIFFLAGS) failed");
+ close(sock);
return -1;
}
@@ -229,6 +233,7 @@
if (fprintf(fp, "%d\n", (int)pid) < 0) {
/* fprintf(3) does not set errno on failure. */
warn("fprintf(%s) failed", path);
+ fclose(fp);
return -1;
}
if (fclose(fp)) {