there are several potential bugs of Memory Leak : I had report these potential bugs in hiredis repo but no respond. =================================================================================== step 1 : In file redis/deps/hiredis/sds.c , function sdscatvprintf line 511 : Allocate memory to buf
step 2 : In file redis/deps/hiredis/sds.c , function sdscatvprintf line 512 : Select the false branch at this point (buf==null is false)
step 3 : In file redis/deps/hiredis/sds.c, function sdscatvprintf line 524 : Select the true branch at this point (buf.[buflen-2]!=0 is true)
step 4 : In file redis/deps/hiredis/sds.c , function sdscatvprintf line 525 : Select the false branch at this point (buf!=staticbuf[0] is false)
step 5 : In file redis/deps/hiredis/sds.c , function sdscatvprintf line 527 : reallocate memory to buf,memory allocated before leaked.
===================================================================================
step 1 : In file redis/deps/hiredis/sds.c , function sdsMakeRoomFor line 223 : Allocate memory to newsh
step 2 : In file redis/deps/hiredis/sds.c , function sdsMakeRoomFor line 224 : Select the false branch at this point (newsh==null is false)
step 3 : In file redis/deps/hiredis/hiredis.c, function redisFormatSdsCommandArgv line 600 : Function sdsMakeRoomFor executes and stores the return value to aux
step 4 : In file redis/deps/hiredis/hiredis.c , function redisFormatSdsCommandArgv line 601 : Select the false branch at this point (aux==null is false)
step 5 : In file redis/deps/hiredis/hiredis.c , function redisFormatSdsCommandArgv line 610 : Select the true branch at this point (j<argc is true)
step 6 : In file redis/deps/hiredis/hiredis.c , function redisFormatSdsCommandArgv line 611 : Select the true branch at this point (argvlen!=null is true)
step 7 : In file redis/deps/hiredis/hiredis.c, function redisFormatSdsCommandArgv line 610 : Select the false branch at this point (i<argc is false)
step 8 : In file redis/deps/hiredis/hiredis.c , function redisFormatSdsCommandArgv line 617 : Select the true branch at this point (sdslen(cmd)==totlen is true), the allocated memory is leaked
===================================================================================
step 1 : In file redis/deps/hiredis/sds.c, function sdscatvprintf line 527 : Allocate memory to buf
step 2 : In file redis/deps/hiredis/sds.c , function sdscatvprintf line 528 : Select the false branch at this point (buf==null is false)
step 3 : In file redis/deps/hiredis/sds.c , function sdscatvprintf line 524 : Select the true branch at this point (buf[buflen-2]!=0 is true)
step 4 : In file redis/deps/hiredis/sds.c, function sdscatvprintf line 525 : Select the false branch at this point (buf.1!=staticbuf[0] is false)
step 5 : In file redis/deps/hiredis/sds.c, function sdscatvprintf line 527 : reallocate memory to buf,memory allocated before leaked.
Comment From: sundb
@Hyxl1017 I tried to reproduce your first leak.
If buf = s_malloc(buflen) is true, then if (buf != staticbuf) will be true, there is no realloc.
Comment From: yoav-steinberg
In the second case I also don't see a leak, target is an output variable of redisFormatSdsCommandArgv so cmd is freed by the caller.
The third case is the same as the first, so @sundb's comment above also applies.
Marking to be closed.