Browse Source

Bugfix: fpgautils: Close product string file from sysfs (autodetect)

Luke Dashjr 12 years ago
parent
commit
6f45c8bd4b
1 changed files with 6 additions and 1 deletions
  1. 6 1
      fpgautils.c

+ 6 - 1
fpgautils.c

@@ -171,6 +171,7 @@ int _serial_autodetect_sysfs(detectone_func_t detectone, va_list needles)
 	char devpath[sizeof(devroot) + (NAME_MAX * 3)];
 	char devpath[sizeof(devroot) + (NAME_MAX * 3)];
 	char buf[0x100];
 	char buf[0x100];
 	char *devfile, *upfile;
 	char *devfile, *upfile;
+	char *rs;
 	char found = 0;
 	char found = 0;
 	size_t len, len2;
 	size_t len, len2;
 	
 	
@@ -187,7 +188,11 @@ int _serial_autodetect_sysfs(detectone_func_t detectone, va_list needles)
 		devfile = upfile + len;
 		devfile = upfile + len;
 		strcpy(devfile, "/product");
 		strcpy(devfile, "/product");
 		F = fopen(devpath, "r");
 		F = fopen(devpath, "r");
-		if (!(F && fgets(buf, sizeof(buf), F)))
+		if (!F)
+			continue;
+		rs = fgets(buf, sizeof(buf), F);
+		fclose(F);
+		if (!rs)
 			continue;
 			continue;
 		
 		
 		if (!SEARCH_NEEDLES(buf))
 		if (!SEARCH_NEEDLES(buf))