Check whether "fflush()" succeeds, and clean up and return an error if