4 ms·
Aren't free()'s senseless before code exits?
by programmernews3 11y ago
Aren't free()'s senseless before code exits?
- syllogism 11y agoIt's best to be rigorous about it in case you refactor or export the function, and to make sure you get a green light from valgrind.
- cperciva 11y agoYes, if you know that the process is going to exit. In this case, the missing free is in a function which is about a dozen calls down in the stack, and I know that it's harmless right now because I've looked at the code and verified that an error there will always result in tarsnap exiting; but if I don't fix this now it's quite possible that in the future I'll have code which uses that function but can tolerate it failing.
- programmernews3 11y agoI think I understand. Function, which could be used independently should free all used resources. If a function is very project-specific and has no purpose to being used independently it may be worth considering declaring it static, right?
- cperciva 11y ago"static" is a different concept -- that marks a function as not being used from outside of that compilation unit (aka .c file). This particular function was used from outside of that file, but was unlikely to be reused in a different project.
- deleted 11y ago[deleted]