Re: OT: Possible memory leak in an exercise of a C handbook
On Tue, Dec 17, 2024 at 16:09:09 -0500, Jeffrey Walton wrote:
> I would rewrite the cleanup code like so:
>
> void dealloc()
> {
> DIGIT *next, *p = head;
> while( p )
> next = p->next, free( p ), p = next;
> }
The logic looks good, but I'm not a fan of this use of the comma operator.
Is that a fashionable thing nowadays?
Especially when teaching a new programmer the ropes, I would stick with
the regular syntax.
void dealloc() {
DIGIT *next, *p = head;
while (p) {
next = p->next;
free(p);
p = next;
}
}
You can put the opening { on the next line if you prefer that way. I
know some people have very strong feeling about that.
Reply to: