Fantastic exchange from DConf
Jack Stouffer via Digitalmars-d
digitalmars-d at puremagic.com
Tue May 9 18:32:33 PDT 2017
On Wednesday, 10 May 2017 at 00:30:42 UTC, H. S. Teoh wrote:
> strncpy(tmp, desc->data1, bufsz);
> if (fwrite(tmp, strlen(tmp), 1, fp) != 1)
> {
> fclose(fp);
> unlink("blah");
> return IO_ERROR;
> }
>
> strncpy(tmp, desc->data2, bufsz);
> if (fwrite(tmp, strlen(tmp), 1, fp) != 1)
> {
> fclose(fp);
> unlink("blah");
> return IO_ERROR;
> }
I think you cause a memory leak in these branches because you
forget to free tmp before returning.
Side note: scope(exit) is one of the best inventions in PLs ever.
More information about the Digitalmars-d
mailing list