From 17ac0f402559f57733fb5da6dafb72cf0f50795f Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 28 Jul 2015 14:01:00 -0400 Subject: [PATCH] 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. --- src/bitcoin-tx.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 9ad57d5c6..e389d51a7 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -143,13 +143,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); }