From 592cc73b5bf19c225b46b976d7c5ea6d9daf0d62 Mon Sep 17 00:00:00 2001 From: Dave Hansen Date: Mon, 4 Oct 2010 16:01:38 -0700 Subject: [PATCH] don't leak FD If this was called and we returned the cached mount, we leak the fopen(). Move the fopen down below the return. --- eyefi-linux.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eyefi-linux.c b/eyefi-linux.c index 224358c..97eccc7 100644 --- a/eyefi-linux.c +++ b/eyefi-linux.c @@ -69,7 +69,7 @@ char *locate_eyefi_mount(void) { static char eyefi_mount[PATHNAME_MAX]; // PATH_MAX anyone? char line[LINEBUFSZ]; - FILE *mounts = fopen("/proc/mounts", "r"); + FILE *mounts; char dev[LINEBUFSZ]; char mnt[LINEBUFSZ]; @@ -77,10 +77,12 @@ char *locate_eyefi_mount(void) char opt[LINEBUFSZ]; int foo; int bar; - + if (strlen(eyefi_mount)) return &eyefi_mount[0]; + mounts = fopen("/proc/mounts", "r"); + while (fgets(&line[0], 1023, mounts)) { int read; read = sscanf(&line[0], "%s %s %s %s %d %d",