This has been something that has bothered me for ages now.
We are all taught in school (at least, I was) that you MUST free every pointer that is allocated. I\'m a
I think that your two examples are actually only one: the free()
should occur only at the end of the process, which as you point out is useless since the process is terminating.
In you second example though, the only difference is that you allow an undefined number of malloc()
, which could lead to running out of memory. The only way to handle the situation is to check the return code of malloc()
and act accordingly.