I guess there is problem with the relation of malloc and goto. Or, I guess there is some wastage of memory or corruption of memory happening out here. Hope, someone can point to me the exact error.
When I compile its not giving me any error, but, my senior is insisting that I have a mistake.
#define FINISH() goto fini;
BOOL Do()
{
BOOL stat;
UINT32 ptr;
int err;
ptr = (UINT32)malloc(1000);
free((void*)ptr);
fini:
return stat;
}
Here are the problems I spotted in the code
err != ERROR_SUCCESSthis function will leak memory. It will jump over thefreecall.mallocinto a 32 bit location. This is not a portable solution. On 64 bit platforms this will wreak havoc on your program as you’d be truncating the address. If you must use a non-pointer type here usesize_tinstead (although I would reccomend a pointer over an integral type)statis not definitively assigned here. You are returning garbage iferr != ERROR_SUCCESS. It needs to always be assigned a value. Easiest way is provide a default.mallocand potentially pass a hiddenNULLpointer intoFun2Here’s the function with the edits I suggested