BUG/MINOR: Fix type passed of sizeof() for calloc()

newsrv->curr_idle_thr is of type `unsigned int`, not `int`. Fix this issue
by simply passing the dereferenced pointer to sizeof, which is the preferred
style anyway.

This bug was introduced in commit dc2f2753e9.
It first appeared in 2.2-dev5. The patch must be backported to 2.2+.

It is notable that the `calloc` call was not introduced within the commit in
question. The allocation was already happening before that commit and it
already looked like it does after applying the patch. Apparently the
argument for the `sizeof` managed to get broken during the rearrangement
that happened in that commit:

     	for (i = 0; i < global.nbthread; i++)
    -		MT_LIST_INIT(&newsrv->idle_orphan_conns[i]);
    -	newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(*newsrv->curr_idle_thr));
    +		MT_LIST_INIT(&newsrv->safe_conns[i]);
    +
    +	newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(int));

Even more notable is that I previously fixed that *exact same* allocation in
commit 017484c80f.

So apparently it was managed to break this single line twice in the same
way for whatever reason there might be.
This commit is contained in:
Tim Duesterhus 2020-09-12 20:26:42 +02:00 committed by Willy Tarreau
parent d344910677
commit b53dd03dc0

View File

@ -3611,7 +3611,7 @@ int check_config_validity()
for (i = 0; i < global.nbthread; i++)
MT_LIST_INIT(&newsrv->safe_conns[i]);
newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(int));
newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(*newsrv->curr_idle_thr));
if (!newsrv->curr_idle_thr)
goto err;
continue;