BUG/MINOR: cli: Fix memory leak

Valgrind's memcheck reports memory leaks in cli.c, because
the out parameter of memprintf is not properly freed:

  ==31035== 11 bytes in 1 blocks are definitely lost in loss record 16 of 101
  ==31035==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==31035==    by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==31035==    by 0x4A3C72: my_realloc2 (standard.h:1364)
  ==31035==    by 0x4A3C72: memvprintf (standard.c:3459)
  ==31035==    by 0x4A3D93: memprintf (standard.c:3482)
  ==31035==    by 0x4AF77E: mworker_cli_sockpair_new (cli.c:2324)
  ==31035==    by 0x48E826: init (haproxy.c:1749)
  ==31035==    by 0x408BBC: main (haproxy.c:2725)
  ==31035==
  ==31035== 11 bytes in 1 blocks are definitely lost in loss record 17 of 101
  ==31035==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==31035==    by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==31035==    by 0x4A3C72: my_realloc2 (standard.h:1364)
  ==31035==    by 0x4A3C72: memvprintf (standard.c:3459)
  ==31035==    by 0x4A3D93: memprintf (standard.c:3482)
  ==31035==    by 0x4AF071: mworker_cli_proxy_create (cli.c:2172)
  ==31035==    by 0x48EC89: init (haproxy.c:1760)
  ==31035==    by 0x408BBC: main (haproxy.c:2725)

These leaks were introduced in commits
ce83b4a5dd and
8a02257d88
which are specific to haproxy 1.9 dev.
This commit is contained in:
Tim Duesterhus 2018-11-22 16:46:50 +01:00 committed by Willy Tarreau
parent 4f93e0c280
commit 4cae3b2f33

View File

@ -2207,8 +2207,12 @@ int mworker_cli_proxy_create()
newsrv->conf.line = 0;
memprintf(&msg, "sockpair@%d", child->ipc_fd[0]);
if ((sk = str2sa_range(msg, &port, &port1, &port2, &errmsg, NULL, NULL, 0)) == 0)
if ((sk = str2sa_range(msg, &port, &port1, &port2, &errmsg, NULL, NULL, 0)) == 0) {
free(msg);
return -1;
}
free(msg);
msg = NULL;
proto = protocol_by_family(sk->ss_family);
if (!proto || !proto->connect) {
@ -2364,9 +2368,12 @@ int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc)
}
if (!str2listener(path, global.stats_fe, bind_conf, "master-socket", 0, &err)) {
free(path);
ha_alert("Cannot create a CLI sockpair listener for process #%d\n", proc);
return -1;
}
free(path);
path = NULL;
list_for_each_entry(l, &bind_conf->listeners, by_bind) {
l->maxconn = global.stats_fe->maxconn;