Visual Studio code analysis picked this up, a C6308.
In function add
, at the line:
dest = (char *) realloc(dest, strlen(dest) + strlen(st) + 1);
...if realloc
fails, dest
is assigned NULL, and the address of the original allocation is clobbered, thus leaking the memory.
C6308 Realloc leak 1504 'realloc' might return null pointer: assigning null pointer to 'dest', which is passed as an argument to 'realloc', will cause the original memory block to be leaked.