dbus1-generator: properly free the FILE*

Also, rework the code to make use of fflush_and_check().

Issue discovered by Simon Danner.