Below code report doubleFree error:
#define S__SUCCESS 0 #define S__FAILURE 1 #define m_err \ if (ctrl->ists != S__SUCCESS) { return ctrl->ists; } void testFunc(CTRL *ctrl) { ctrl->ists = S__FAILURE; } int main() { char lpMsg = NULL; CTRL ctrlw, *ctrl=&ctrlw; if ((lpMsg = malloc(256 * sizeof(char))) == NULL) return 1; memset(lpMsg, 0x00, sizeof(256 * sizeof(char)); testFunc(ctrl); if (ctrl->ists != S__SUCCESS) { free(lpMsg); //lpMsg = NULL; } m_err; strcpy(lpMsg, "Hello"); printf("lpMsg=%s\n", lpMsg); if (lpMsg != NULL) free(lpMsg); return 0; }
if I uncomment the code lpMsg = NULL; then no doubleFree error will be reported!
lpMsg = NULL;
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11874
Log in to post a comment.
Below code report doubleFree error:
if I uncomment the code
lpMsg = NULL;
then no doubleFree error will be reported!Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11874