4 ms·
It's presumably to reduce the number of places where you might need to call free, and then fail to do so? (This might already be happening in line 580? Though
by tom_ 3y ago
It's presumably to reduce the number of places where you might need to call free, and then fail to do so?
(This might already be happening in line 580? Though in practice perhaps that case never occurs.)
- hnarn 3y agoHow to get your open source project peer reviewed: post an LLM bug report, post it to HN and scour the comments for people reviewing your code ;-)
- rstuart4133 3y agoI doubt it's to reduce the number of calls to free. After all, there must be exactly one call to free() for every call to malloc(). It looks more like a coding habit this particular programmer uses to avoid forgetting to call free(). He puts it as close to the call to malloc() as possible, which reduces the changes of forgetting. It's interesting code to look at, if you are a C programmer. As you noted, his heroic efforts to always call free fails if line 580 gets executed. It never will of course, so him adding 580 reveals a certain paranoia. Perfectly understandable in a C programmer, but for most line 578 would be enough to assuage the paranoia. Others (me, for instance) would make 578 an assert, and get rid of 580. At the 1000ft level the result is the presumably the same in both cases: the program exits after printing an error on stderr, but the error message will be different. The assert makes it plain it's an internal failure, but the current method may be mistaken for a externally triggered error. Or he could have sidestepped the overflow checks and free() by using salloc() - but maybe it doesn't exist on platforms he ports to. I would do a lot of other things differently too. I guess it just shows the way old C programmers deal with the repeated beatings inflicted by the language varies a lot.
- tom_ 3y agoOne call per path through the code, but potentially multiple calls lexically!