On Wed, Feb 05, 2014 at 12:56:20PM +0100, Paul Winter wrote: > Hi list, >
Hi, > I'm currently trying to get familiar with OpenBSD source code and I've > noticed > that there are fclose() function calls missing sometimes. (e.g. > usr.bin/awk/maketab.c, usr.sbin/smtpd/table_passwd.c). > Where do you think a fclose() is missing in table_passwd.c and maketab.c ? As far as table_passwd.c is concerned, I read the file again and don't see a fp leak there. > I'd like to ask whether these files are intended to be closed by operating > system when the utility exits or fclose() calls just has been forgotten. > When a utility exits, we don't necessarily release resources because they are unallocated by the operating system, it would add useless code. > My personal view is that program should always call free, fclose and such > even when exiting immediately after. For purpose of clean and transparent > code and logic and for purpose of code reusability. But perhaps there are > some reasons not to do that I'm missing. > Well, first of all it's redundant as said above, as for clean and transparent code since you're exiting anyway the need for bookkeeping isn't that valuable. Furthermore, I think it was Theo who explained this a while ago, but if for example you are following an error path because someone managed to corrupt your allocator's internal state, the last thing you want to do is call free() in your error path to give him another chance at exploiting the situation. -- Gilles Chehade https://www.poolp.org @poolpOrg

