From f6355e69183f20c3d1fd1b9adbb4f3a00ad680ac 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 c82d4f93a..40b4a38e4 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -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); }