Fixed ledger read fd leak. Reordered subsystem init. (#138)

This commit is contained in:
Ravin Perera
2020-10-26 08:11:55 +05:30
committed by GitHub
parent a60444b57f
commit 116a54e980
3 changed files with 15 additions and 11 deletions

View File

@@ -333,6 +333,7 @@ namespace ledger
struct stat st;
if (fstat(fd, &st) == -1)
{
close(fd);
LOG_ERROR << errno << ": Error in ledger file stat. " << file_path;
return -1;
}
@@ -340,10 +341,12 @@ namespace ledger
buffer.resize(st.st_size);
if (read(fd, buffer.data(), buffer.size()) == -1)
{
close(fd);
LOG_ERROR << errno << ": Error reading ledger file. " << file_path;
return -1;
}
close(fd);
return 0;
}

View File

@@ -68,14 +68,14 @@ int parse_cmd(int argc, char **argv)
*/
void deinit()
{
consensus::deinit();
ledger::deinit();
state_sync::deinit();
state_serve::deinit();
read_req::deinit();
sc::deinit();
usr::deinit();
p2p::deinit();
read_req::deinit();
consensus::deinit();
state_sync::deinit();
state_serve::deinit();
sc::deinit();
ledger::deinit();
}
void sigint_handler(int signum)
@@ -192,14 +192,14 @@ int main(int argc, char **argv)
<< (conf::cfg.startup_mode == conf::OPERATING_MODE::OBSERVER ? "Observer" : "Proposer");
LOG_INFO << "Public key: " << conf::cfg.pubkeyhex.substr(2); // Public key without 'ed' prefix.
if (p2p::init() != 0 ||
usr::init() != 0 ||
if (ledger::init() ||
sc::init() ||
read_req::init() != 0 ||
state_serve::init() != 0 ||
state_sync::init() != 0 ||
ledger::init() ||
consensus::init() != 0)
consensus::init() != 0 ||
read_req::init() != 0 ||
p2p::init() != 0 ||
usr::init() != 0)
{
deinit();
return -1;

View File

@@ -310,6 +310,7 @@ namespace sc
// Write the json message and close write fd.
if (write(stdinpipe[1], json.data(), json.size()) == -1)
{
close(stdinpipe[1]);
LOG_ERROR << errno << ": Failed to write to stdin of contract process.";
return -1;
}