In the example shown it may cause a problem. It is called dangling pointer .
The free()
is acting on the palavra
variable that was not initialized. That is, in C, has a value in it, you have no idea what value this is, will vary in each execution of the generated application. It will attempt to release the memory pointed to by that address. If you get lucky you can just fail and nothing happens or you can get rid of something that was allotted and should not. Something disastrous can happen and even deallocate things completely out of the way expected, since even the size of the allocation can be erroneously considered by free()
. The information is virtually random.
In C we have to be very careful. One such care is to always initialize the variable. This would cause the wrong%% to not cause problems, even though the code would not be strictly correct. The ideal is not to leave a free()
free like this (I did not resist :)). It goes that someday someone changes something and it happens to be a problem even in cases where it was not initially.