chiark / gitweb /
conf-parser: don't close FILE* object if we didn't open it
authorLennart Poettering <lennart@poettering.net>
Tue, 6 Apr 2010 00:36:41 +0000 (02:36 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 6 Apr 2010 00:36:41 +0000 (02:36 +0200)
conf-parser.c

index 4075465b2496719bfec6275eddc22d4c68f55e99..aebf61aaf5067a77086be7594c0d0b14506b95dc 100644 (file)
@@ -135,6 +135,7 @@ int config_parse(const char *filename, FILE *f, const char* const * sections, co
         unsigned line = 0;
         char *section = NULL;
         int r;
+        bool ours = false;
 
         assert(filename);
         assert(t);
@@ -145,6 +146,8 @@ int config_parse(const char *filename, FILE *f, const char* const * sections, co
                         log_error("Failed to open configuration file '%s': %s", filename, strerror(-r));
                         goto finish;
                 }
+
+                ours = true;
         }
 
         while (!feof(f)) {
@@ -168,7 +171,7 @@ int config_parse(const char *filename, FILE *f, const char* const * sections, co
 finish:
         free(section);
 
-        if (f)
+        if (f && ours)
                 fclose(f);
 
         return r;