This a short snippet of code, with two calls to exit(3)
in case of failure.
Do these calls deallocate memory allocated by malloc? Google search once says it does, and even more times, it doesn't...
Should I add free()?
Also: which is better if (!word)
(it would also work for eg. word == 0 which is different from word == NULL, so I guess it is wrong) or if (word == NULL)
?
char *word = NULL, *temp = NULL;
word = (char *)malloc(sizeof(char) * size);
if (!word) { /* or maybe rather it should be (word == NULL) */
perror("malloc fail");
if (fclose(fp)) {
perror("fclose fail");
exit(3); /* exit without free ? */
}
exit(3); /* exit without free ? */
}
Thanks in advance!