diff --git a/NEWS b/NEWS
index 63b6ba4e93d40ad1f5322a38d432c5a39dd24abd..f312b9dcbf4b00d4b28dd1e1102412767af24f39 100644
--- a/NEWS
+++ b/NEWS
@@ -210,6 +210,7 @@ documents those changes that are of interest to users and admins.
     Gerrit Renker (CSCS).
  -- Fixed Regression from 2.2.4 in accounting where an inherited limit
     would not be set correctly in the added child association.
+ -- Fixed issue with accounting when asking for jobs with a hostlist.
 
 * Changes in SLURM 2.2.6
 ========================
diff --git a/src/plugins/accounting_storage/mysql/as_mysql_jobacct_process.c b/src/plugins/accounting_storage/mysql/as_mysql_jobacct_process.c
index c03e4ec28c81e51a745c0b6fbed7201e3f00e47b..063ed19fc7d92793d8ccf645a381b8830020c556 100644
--- a/src/plugins/accounting_storage/mysql/as_mysql_jobacct_process.c
+++ b/src/plugins/accounting_storage/mysql/as_mysql_jobacct_process.c
@@ -844,7 +844,7 @@ extern List setup_cluster_list_with_inx(mysql_conn_t *mysql_conn,
 	}
 
 	temp_hl = hostlist_create(job_cond->used_nodes);
-	if (!hostlist_count(temp_hl)) {
+	if (hostlist_count(temp_hl) <= 0) {
 		error("we didn't get any real hosts to look for.");
 		goto no_hosts;
 	}
@@ -870,8 +870,7 @@ extern List setup_cluster_list_with_inx(mysql_conn_t *mysql_conn,
 	       mysql_conn->conn, THIS_FILE, __LINE__, query);
 	if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
 		xfree(query);
-		hostlist_destroy(temp_hl);
-		return NULL;
+		goto no_hosts;
 	}
 	xfree(query);
 
@@ -903,14 +902,16 @@ extern List setup_cluster_list_with_inx(mysql_conn_t *mysql_conn,
 			_destroy_local_cluster(local_cluster);
 	}
 	mysql_free_result(result);
-	hostlist_iterator_destroy(h_itr);
+
 	if (!list_count(local_cluster_list)) {
-		hostlist_destroy(temp_hl);
 		list_destroy(local_cluster_list);
-		return NULL;
+		local_cluster_list = NULL;
+		goto no_hosts;
 	}
+
 no_hosts:
 
+	hostlist_iterator_destroy(h_itr);
 	hostlist_destroy(temp_hl);
 
 	return local_cluster_list;