Skip to content

Commit

Permalink
Fix memory leak in http server (triton-inference-server#5521)
Browse files Browse the repository at this point in the history
* Fix memory leak in http server

* Fix additional memory leaks
  • Loading branch information
Tabrizian authored Mar 20, 2023
1 parent 1340078 commit ed554d8
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ HTTPAPIServer::EVBufferToInput(
AllocPayload::OutputInfo::JSON;

triton::common::TritonJson::Value params_json;
if (request_json.MemberAsObject("parameters", &params_json) == nullptr) {
if (request_json.Find("parameters", &params_json)) {
std::vector<std::string> parameters;
RETURN_MSG_IF_ERR(
params_json.Members(&parameters), "failed to get request params.");
Expand All @@ -2367,7 +2367,10 @@ HTTPAPIServer::EVBufferToInput(
if (parameter == "sequence_id") {
uint64_t seq_id;
// Try to parse sequence_id as uint64_t
if (params_json.MemberAsUInt(parameter.c_str(), &seq_id) != nullptr) {
TRITONSERVER_Error* err;
if ((err = params_json.MemberAsUInt(parameter.c_str(), &seq_id)) !=
nullptr) {
TRITONSERVER_ErrorDelete(err);
// On failure try to parse as a string
std::string seq_id;
RETURN_MSG_IF_ERR(
Expand Down Expand Up @@ -2425,27 +2428,44 @@ HTTPAPIServer::EVBufferToInput(
std::string string_value;
int64_t int_value;
bool bool_value;
if (params_json.MemberAsString(parameter.c_str(), &string_value) ==
nullptr) {
TRITONSERVER_Error* err;

// String parsing
if ((err = params_json.MemberAsString(
parameter.c_str(), &string_value)) != nullptr) {
TRITONSERVER_ErrorDelete(err);
} else {
RETURN_IF_ERR(TRITONSERVER_InferenceRequestSetStringParameter(
irequest, parameter.c_str(), string_value.c_str()));
} else if (
params_json.MemberAsInt(parameter.c_str(), &int_value) == nullptr) {
continue;
}

// Int parsing
if ((err = params_json.MemberAsInt(parameter.c_str(), &int_value)) !=
nullptr) {
TRITONSERVER_ErrorDelete(err);
} else {
RETURN_IF_ERR(TRITONSERVER_InferenceRequestSetIntParameter(
irequest, parameter.c_str(), int_value));
} else if (
params_json.MemberAsBool(parameter.c_str(), &bool_value) ==
continue;
}

// bool parsing
if ((err = params_json.MemberAsBool(parameter.c_str(), &bool_value)) !=
nullptr) {
TRITONSERVER_ErrorDelete(err);
} else {
RETURN_IF_ERR(TRITONSERVER_InferenceRequestSetBoolParameter(
irequest, parameter.c_str(), bool_value));
} else {
return TRITONSERVER_ErrorNew(
TRITONSERVER_ERROR_INVALID_ARG,
("parameter '" + parameter +
"' has invalid type. It should be either "
"'int', 'bool', or 'string'.")
.c_str());
continue;
}

return TRITONSERVER_ErrorNew(
TRITONSERVER_ERROR_INVALID_ARG,
("parameter '" + parameter +
"' has invalid type. It should be either "
"'int', 'bool', or 'string'.")
.c_str());
}
}

Expand Down

0 comments on commit ed554d8

Please sign in to comment.