diff --git a/llarp/service/identity.cpp b/llarp/service/identity.cpp index f54a025a5..a28bb2204 100644 --- a/llarp/service/identity.cpp +++ b/llarp/service/identity.cpp @@ -80,7 +80,6 @@ namespace llarp Clear(); std::array tmp; - llarp_buffer_t buf(tmp); // this can throw bool exists = fs::exists(fname); @@ -94,6 +93,7 @@ namespace llarp // check for file if (!exists) { + llarp_buffer_t buf{tmp}; // regen and encode RegenerateKeys(); if (!BEncode(&buf)) @@ -108,6 +108,7 @@ namespace llarp { throw std::runtime_error{fmt::format("failed to write {}: {}", fname, e.what())}; } + return; } if (not fs::is_regular_file(fname)) @@ -125,10 +126,11 @@ namespace llarp throw std::length_error{"service identity too big"}; } // (don't catch io error exceptions) - - if (!bencode_decode_dict(*this, &buf)) - throw std::length_error{"could not decode service identity"}; - + { + llarp_buffer_t buf{tmp}; + if (!bencode_decode_dict(*this, &buf)) + throw std::length_error{"could not decode service identity"}; + } auto crypto = CryptoManager::instance(); // ensure that the encryption key is set