6 ms·
Passing a null pointer to free() is perfectly safe, and in this case simplifies the cleanup code. Although the concern of a memory leak is valid. I would have
by protopete 11y ago
Passing a null pointer to free() is perfectly safe, and in this case simplifies the cleanup code.
Although the concern of a memory leak is valid. I would have expected the resources to be free'd regardless of the result.
- luso_brazilian 11y agoOf course, you are right. I seem to have carried the belief that freeing a null pointer was as bad as freeing one twice. And now I know. Seems to be a common misconception [1], thanks for pointing out, that makes the GGP code correct in all counts and my switch redundant. [1] https://news.ycombinator.com/item?id=8844031 https://news.ycombinator.com/item?id=8844031