On Fri, 22.08.14 08:19, Simon Danner ([email protected]) wrote: > In the !service case, the first file doesn't get closed automatically, > since the second one uses the same FILE*. Close it explicitly. > Found by cppcheck > > Signed-off-by: Simon Danner <[email protected]> > --- > src/dbus1-generator/dbus1-generator.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/src/dbus1-generator/dbus1-generator.c > b/src/dbus1-generator/dbus1-generator.c > index e1ffc55..e401471 100644 > --- a/src/dbus1-generator/dbus1-generator.c > +++ b/src/dbus1-generator/dbus1-generator.c > @@ -100,8 +100,7 @@ static int create_dbus_files( > } > } > > - fflush(f); > - if (ferror(f)) { > + if (fclose(f)) { > log_error("Failed to write %s: %m", a); > return -errno; > }
It's actually more complicated. We need to set f to NULL too, otherwise the cleanup logic might invoke fclose() again, on an invalidated FILE*. I have now commited a patch that reworks this to use fflush_and_check() and then closes the thing and resets f to NULL. Thanks for the pointer! Lennart -- Lennart Poettering, Red Hat _______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
