Perhaps replace the last few statements with
```c
bool retval = fputs((char *)p, fd) >= 0;
free(p);
return retval;
```