  			continue;
  		a = info->hw_works[i];
  		b = info->local_works[i];
-@@ -843,31 +964,31 @@ static struct api_data *avalon2_api_stats(struct cgpu_info *cgpu)
+@@ -843,31 +968,31 @@ static struct api_data *avalon2_api_stats(struct cgpu_info *cgpu)
  		root = api_add_percent(root, buf, &hwp, true);
  	}
  	for (i = 0; i < 2 * AVA2_DEFAULT_MODULARS; i++) {

 	avalon2_init_pkg(&pkg, AVA2_P_JOB_ID, 1, 1);
 	while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 		;
@@ -576,6 +638,7 @@ static bool avalon2_detect_one(const char *devpath)
 		memcpy(mm_version[i], ret_pkg.data, 15);
 		mm_version[i][15] = '\0';
 	}
+	avalon2_close(fd);
 	if (!modular[0] && !modular[1] && !modular[2] && !modular[3])
 		return false;
 
@@ -595,28 +658,27 @@ static bool avalon2_detect_one(const char *devpath)
 
 	info = avalon2->device_data;
 

 
 	struct pool *pool;
 	struct cgpu_info *avalon2 = thr->cgpu;
@@ -696,16 +826,11 @@ static int64_t avalon2_scanhash(struct thr_info *thr)
 	uint32_t tmp, range, start;
 	int i;
 
