Skip to content

Commit

Permalink
fixed fd leak
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfireitdiy authored May 19, 2021
1 parent 1971682 commit 298ea6a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/jsonrpccpp/client/connectors/unixdomainsocketclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ void UnixDomainSocketClient::SendRPCMessage(const std::string &message,

if (connect(socket_fd, (struct sockaddr *)&address, sizeof(sockaddr_un)) !=
0) {
close(socket_fd);
throw JsonRpcException(Errors::ERROR_CLIENT_CONNECTOR,
"Could not connect to: " + this->path);
}

StreamWriter writer;
string toSend = message + DEFAULT_DELIMITER_CHAR;
if (!writer.Write(toSend, socket_fd)) {
close(socket_fd);
throw JsonRpcException(Errors::ERROR_CLIENT_CONNECTOR,
"Could not write request");
}

StreamReader reader(DEFAULT_BUFFER_SIZE);
if (!reader.Read(result, socket_fd, DEFAULT_DELIMITER_CHAR)) {
close(socket_fd);
throw JsonRpcException(Errors::ERROR_CLIENT_CONNECTOR,
"Could not read response");
}
Expand Down

0 comments on commit 298ea6a

Please sign in to comment.