[6.0] de72059f3 Plug a few more leaks
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Thu Aug 16 08:52:43 UTC 2018
commit de72059f33c4fbc24f76d865842d2d90dad2f049
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 6776e88d7..8ad4a5a16 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 c66b8a2cd..116efdd02 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 0a0cb6dbe..4b2f608fc 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 db07d42c9..edfe79653 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 8f917d4f8..2c458f3d6 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 72108b1a6..d7ceefe89 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 735b747fa..add0f1f46 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 71ef165aa..8da7c56ef 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 1307cd5fb..ca8c6a5d4 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