BUG/MINOR: check: fix leak on add dynamic server with agent-check error

If an error occured during a dynamic server creation, free_check is used
to liberate a possible agent-check. However, this does not free
associated vars and rules associated as this is done on another function
named deinit_srv_agent_check.

To simplify the check free and avoid a leak, move free vars/rules in
free_check. This is valid because deinit_srv_agent_check also uses
free_check.

This operation is done only for an agent-check because for a health
check, the proxy instance is the owner of check vars/rules.

This should not be backported, unless dynamic server checks are
backported.
diff --git a/src/check.c b/src/check.c
index 8ad32fe..6225cc8 100644
--- a/src/check.c
+++ b/src/check.c
@@ -1337,11 +1337,19 @@
 
 /* Liberates the resources allocated for a check.
  *
- * This function must only be used at startup when it is known that the check
- * has never been executed.
+ * This function must only be run by the thread owning the check.
  */
 void free_check(struct check *check)
 {
+	/* For agent-check, free the rules / vars from the server. This is not
+	 * done for health-check : the proxy is the owner of the rules / vars
+	 * in this case.
+	 */
+	if (check->state & CHK_ST_AGENT) {
+		free_tcpcheck_vars(&check->tcpcheck_rules->preset_vars);
+		ha_free(&check->tcpcheck_rules);
+	}
+
 	task_destroy(check->task);
 	if (check->wait_list.tasklet)
 		tasklet_free(check->wait_list.tasklet);
@@ -1763,11 +1771,6 @@
 
 static void deinit_srv_agent_check(struct server *srv)
 {
-	if (srv->agent.tcpcheck_rules) {
-		free_tcpcheck_vars(&srv->agent.tcpcheck_rules->preset_vars);
-		ha_free(&srv->agent.tcpcheck_rules);
-	}
-
 	if (srv->agent.state & CHK_ST_CONFIGURED)
 		free_check(&srv->agent);