ConfigParser: call fclose() using AtScopeExit()
authorMax Kellermann <max@musicpd.org>
Sat, 14 Sep 2019 11:10:25 +0000 (13:10 +0200)
committerMax Kellermann <max@musicpd.org>
Sat, 14 Sep 2019 11:10:25 +0000 (13:10 +0200)
src/ConfigParser.cxx

index 8a90a5e..6574f9e 100644 (file)
@@ -34,6 +34,7 @@
 #include "util/Compiler.h"
 #include "util/PrintException.hxx"
 #include "util/RuntimeError.hxx"
+#include "util/ScopeExit.hxx"
 #include "util/StringStrip.hxx"
 
 #include <algorithm>
@@ -647,6 +648,8 @@ ReadConfigFile(const char *filename)
                return false;
        }
 
+       AtScopeExit(file) { fclose(file); };
+
        unsigned no = 0;
        char line[MAX_LINE_LENGTH];
        while (fgets(line, sizeof(line), file) != nullptr) {
@@ -667,6 +670,5 @@ ReadConfigFile(const char *filename)
                }
        }
 
-       fclose(file);
        return true;
 }