1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/* * Rule: MEM04-C * Source: wiki * Status: PASS - Should NOT trigger MEM04-C violation */ size_t nsize; /* Initialize nsize */ char *p2; char *p = (char *)malloc(100); if (p == NULL) { /* Handle error */ } /* ... */ p2 = NULL; if (nsize != 0) { p2 = (char *)realloc(p, nsize); } if (p2 == NULL) { free(p); p = NULL; return NULL; } p = p2;