BUG/MINOR: sink/log: properly deinit srv in sink_new_from_logsrv()

When errors are encountered in sink_new_from_logsrv() function,
incompetely allocated ressources are freed to prevent memory leaks.

For instance: logsrv implicit server is manually cleaned up on error prior
to returning from the function.

However, since 198e92a8e5 ("MINOR: server: add a global list of all known
servers") every server created using new_server() is registered to the
global list, but unfortunately the manual srv cleanup in
sink_new_from_logsrv() doesn't remove the srv from the global list, so the
freed server will still be referenced there, which can result in invalid
reads later.

Moreover, server API has evolved since, and now the srv_drop() function is
available for that purpose, so let's use it, but make sure that srv is
freed before the proxy because on older versions srv_drop() expects the
srv to be linked to a valid proxy pointer.

This must be backported up to 2.4.

[For 2.4 version, free_server() must be used instead of srv_drop()]

(cherry picked from commit c38cf3cf98d30d6d069c36d3d475511d892201b9)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 9da1f958ec5b851ace279e35dcb26f0a9a6d71c9)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 958e7196f8235f1a93cbc3bf440917746abeff4f)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 350e6885733c70809cce2e4ba74fa6a3da98266f)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/sink.c b/src/sink.c
index 3a6cae7..4d811eb 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -1079,6 +1079,9 @@
 
 	return sink;
 error:
+	if (srv)
+		free_server(srv);
+
 	if (p) {
 		if (p->id)
 			free(p->id);
@@ -1088,16 +1091,6 @@
 		free(p);
 	}
 
-	if (srv) {
-		if (srv->id)
-			free(srv->id);
-		if (srv->conf.file)
-			free((void *)srv->conf.file);
-		if (srv->per_thr)
-		       free(srv->per_thr);
-		free(srv);
-	}
-
 	if (sft)
 		free(sft);