[master] 091e29b Plug a few more leaks

Federico G. Schwindt fgsch at lodoss.net
Sat Apr 14 09:32:11 UTC 2018


commit 091e29badc49e8c22589be17d748f8d337ae1086
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Sat Apr 14 08:56:29 2018 +0100

    Plug a few more leaks

diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 6776e88..8ad4a5a 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -96,7 +96,7 @@ void cmd_server_gen_haproxy_conf(struct vsb *vsb);
 
 void vtc_loginit(char *buf, unsigned buflen);
 struct vtclog *vtc_logopen(const char *id);
-void vtc_logclose(struct vtclog *vl);
+void vtc_logclose(void *arg);
 void vtc_log(struct vtclog *vl, int lvl, const char *fmt, ...)
     v_printflike_(3, 4);
 void vtc_fatal(struct vtclog *vl, const char *, ...)
diff --git a/bin/varnishtest/vtc_barrier.c b/bin/varnishtest/vtc_barrier.c
index c66b8a2..116efdd 100644
--- a/bin/varnishtest/vtc_barrier.c
+++ b/bin/varnishtest/vtc_barrier.c
@@ -137,7 +137,7 @@ barrier_sock_thread(void *priv)
 	AZ(pthread_mutex_lock(&b->mtx));
 
 	vl = vtc_logopen(b->name);
-	AN(vl);
+	pthread_cleanup_push(vtc_logclose, vl);
 
 	sock = VTCP_listen_on("127.0.0.1:0", NULL, b->expected, &err);
 	if (sock < 0) {
@@ -219,7 +219,7 @@ barrier_sock_thread(void *priv)
 	macro_undef(vl, b->name, "sock");
 	closefd(&sock);
 	free(conns);
-
+	pthread_cleanup_pop(1);
 	return (NULL);
 }
 
diff --git a/bin/varnishtest/vtc_client.c b/bin/varnishtest/vtc_client.c
index 0a0cb6d..4b2f608 100644
--- a/bin/varnishtest/vtc_client.c
+++ b/bin/varnishtest/vtc_client.c
@@ -207,6 +207,7 @@ client_thread(void *priv)
 	AN(*c->connect);
 
 	vl = vtc_logopen(c->name);
+	pthread_cleanup_push(vtc_logclose, vl);
 
 	vsb = macro_expand(vl, c->connect);
 	AN(vsb);
@@ -236,6 +237,7 @@ client_thread(void *priv)
 	}
 	vtc_log(vl, 2, "Ending");
 	VSB_destroy(&vsb);
+	pthread_cleanup_pop(1);
 	return (NULL);
 }
 
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index db07d42..edfe796 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -1865,6 +1865,21 @@ const struct cmds http_cmds[] = {
 	{ NULL, NULL }
 };
 
+static void
+http_process_cleanup(void *arg)
+{
+	struct http *hp = arg;
+
+	if (hp->h2)
+		stop_h2(hp);
+	VSB_destroy(&hp->vsb);
+	free(hp->rxbuf);
+	free(hp->rem_ip);
+	free(hp->rem_port);
+	free(hp->rem_path);
+	FREE_OBJ(hp);
+}
+
 int
 http_process(struct vtclog *vl, const char *spec, int sock, int *sfd,
 	     const char *addr)
@@ -1906,16 +1921,10 @@ http_process(struct vtclog *vl, const char *spec, int sock, int *sfd,
 		strcpy(hp->rem_port, "0");
 		hp->rem_path = strdup(addr);
 	}
+	pthread_cleanup_push(http_process_cleanup, hp);
 	parse_string(spec, http_cmds, hp, vl);
-	if (hp->h2)
-		stop_h2(hp);
 	retval = hp->fd;
-	VSB_destroy(&hp->vsb);
-	free(hp->rxbuf);
-	free(hp->rem_ip);
-	free(hp->rem_port);
-	free(hp->rem_path);
-	FREE_OBJ(hp);
+	pthread_cleanup_pop(1);
 	return (retval);
 }
 
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index 8f917d4..2c458f3 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -2541,6 +2541,7 @@ static void
 stream_delete(struct stream *s)
 {
 	CHECK_OBJ_NOTNULL(s, STREAM_MAGIC);
+	free(s->body);
 	free(s->spec);
 	free(s->name);
 	FREE_OBJ(s);
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index 72108b1..d7ceefe 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -90,8 +90,9 @@ vtc_logopen(const char *id)
 }
 
 void
-vtc_logclose(struct vtclog *vl)
+vtc_logclose(void *arg)
 {
+	struct vtclog *vl = arg;
 
 	CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC);
 	if (pthread_getspecific(log_key) == vl)
diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c
index 735b747..add0f1f 100644
--- a/bin/varnishtest/vtc_logexp.c
+++ b/bin/varnishtest/vtc_logexp.c
@@ -194,6 +194,7 @@ logexp_delete(struct logexp *le)
 	free(le->vname);
 	free(le->query);
 	VSM_Destroy(&le->vsm);
+	vtc_logclose(le->vl);
 	FREE_OBJ(le);
 }
 
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index 71ef165..8da7c56 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -240,8 +240,10 @@ tst_cb(const struct vev *ve, int what)
 			    jp->tst->filename,
 			    ecode ? "skipped" : "passed", t);
 		}
-		if (jp->evt != NULL)
+		if (jp->evt != NULL) {
 			VEV_Stop(vb, jp->evt);
+			free(jp->evt);
+		}
 
 		FREE_OBJ(jp);
 		return (1);
diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c
index 1307cd5..ca8c6a5 100644
--- a/bin/varnishtest/vtc_server.c
+++ b/bin/varnishtest/vtc_server.c
@@ -232,6 +232,7 @@ server_thread(void *priv)
 	assert(s->sock >= 0);
 
 	vl = vtc_logopen(s->name);
+	pthread_cleanup_push(vtc_logclose, vl);
 
 	vtc_log(vl, 2, "Started on %s", s->listen);
 	for (i = 0; i < s->repeat; i++) {
@@ -255,6 +256,7 @@ server_thread(void *priv)
 		VTCP_close(&fd);
 	}
 	vtc_log(vl, 2, "Ending");
+	pthread_cleanup_pop(1);
 	return (NULL);
 }
 
@@ -288,6 +290,7 @@ server_dispatch_wrk(void *priv)
 	assert(s->sock < 0);
 
 	vl = vtc_logopen(s->name);
+	pthread_cleanup_push(vtc_logclose, vl);
 
 	fd = s->fd;
 
@@ -299,6 +302,7 @@ server_dispatch_wrk(void *priv)
 		vtc_fatal(vl, "Shutdown failed: %s", strerror(errno));
 	VTCP_close(&s->fd);
 	vtc_log(vl, 2, "Ending");
+	pthread_cleanup_pop(1);
 	return (NULL);
 }
 
@@ -317,7 +321,8 @@ server_dispatch_thread(void *priv)
 	assert(s->sock >= 0);
 
 	vl = vtc_logopen(s->name);
-	AN(vl);
+	pthread_cleanup_push(vtc_logclose, vl);
+
 	vtc_log(vl, 2, "Dispatch started on %s", s->listen);
 
 	while (1) {
@@ -335,6 +340,7 @@ server_dispatch_thread(void *priv)
 		s2->run = 1;
 		AZ(pthread_create(&s2->tp, NULL, server_dispatch_wrk, s2));
 	}
+	pthread_cleanup_pop(1);
 	NEEDLESS(return(NULL));
 }
 


More information about the varnish-commit mailing list