On 8/11/21 03:24, Bill Somerville via wsjt-devel wrote:
On 11/08/2021 04:04, Phil Karn via wsjt-devel wrote:
In wsprd.c/writec2file() the output file is opened for writing but never
closed.

--Phil

Hi Phil,

Thanks! Repaired for the next release.


You're welcome!

A general suggestion. When I do a lot of dynamic allocation, be it malloc/free or fopen/fclose, I try to NULL each pointer immediately after I close it. E.g.,

fclose(stream); stream = NULL;

free(buf); buf = NULL;

This makes it much harder to accidentally reuse a file or buffer pointer after it has been freed, as doing so will usually trigger an immediate segfault from dereferencing the null pointer. This can be taken to silly extremes, e.g., when a series of free() calls is immediately followed by an exit() or return, but in general I try to do it because I know I'm probably going to change something later and introduce a subtle bug. I've done it *many* times...

I wish the C libraries had done this from the beginning, eg, by defining fclose() and free() as taking the *address* of a pointer so they could automatically null it as a side effect. But here we are, 50 years later...

73, Phil






_______________________________________________
wsjt-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wsjt-devel

Reply via email to