gpio: fix resource leaks
Signed-off-by: Sanjay Singh Rawat <sanjay.rawat@linaro.org>
diff --git a/gpio.c b/gpio.c
index 39480b0..3c02b8e 100644
--- a/gpio.c
+++ b/gpio.c
@@ -325,7 +325,7 @@
FILE *fgpio, *fgpio_export;
int i, gpio_max = 0;
char *line = NULL;
- ssize_t read, len;
+ ssize_t read, len = 0;
fgpio = fopen("/sys/kernel/debug/gpio", "r");
if (!fgpio) {
@@ -353,7 +353,15 @@
if (system(command) < 0)
printf("error: failed to export gpio-%d\n", i);
}
+
+ free(line);
out:
+ if (fgpio)
+ fclose(fgpio);
+
+ if (fgpio_export)
+ fclose(fgpio_export);
+
return;
}