2 ms·
In LibreSSL, we went big hammer and clear all the bignums, regardless of sensitivity. And so it was that when I bumped into Colin at BSDCan 2014 two weeks later
by cperciva 11y ago
In LibreSSL, we went big hammer and clear all the bignums, regardless of sensitivity. And so it was that when I bumped into Colin at BSDCan 2014 two weeks later, failure to clear secret bignums from memory was fresh in my mind.
I bumped into Ted again three weeks ago at BSDCan 2015 and he must have had memory leaks on his mind, because the day after the conference ended he sent me an email pointing out a memory leak in Tarsnap. (Harmless, since it's in a we're-about-to-exit error path, but worth $10 anyway.)
- programmernews3 11y agoAren'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]