Commit 091e29ba authored by Federico G. Schwindt's avatar Federico G. Schwindt

Plug a few more leaks

parent 49f3387c
......@@ -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 *, ...)
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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)
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment