If you put that fwrite in the `else` block of `if (fp == NULL)`, then you can drop the cleanup label and the goto cleanup.