Avoid leaking file descriptors in RegisterLoad

This is pretty trivial, but if there's an error here we'll leak a file
descriptor. Changed it to always close the file.
This commit is contained in:
Casey Rodarmor 2015-07-28 14:01:00 -04:00 committed by Luke Dashjr
parent 60457d3c2f
commit f6355e6918
1 changed files with 4 additions and 3 deletions

View File

@ -142,13 +142,14 @@ static void RegisterLoad(const string& strInput)
valStr.insert(valStr.size(), buf, bread);
}
if (ferror(f)) {
int error = ferror(f);
fclose(f);
if (error) {
string strErr = "Error reading file " + filename;
throw runtime_error(strErr);
}
fclose(f);
// evaluate as JSON buffer register
RegisterSetJson(key, valStr);
}