By looking at following code statements, unsigned char response[20] ; UINT *rspSize; rspSize = (PUINT)malloc(sizeof(UINT)); result = ezLinkRcv(response,rspSize); it seems like problem with rspSize, rspSize doesn't match with response memory allocatin i.e. 20. I suggest you to try out giving hard-coded 20 instead of rspSize to know exact problem and then after implement generalized logic.