Skip to content

Commit

Permalink
Fix memory deallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
erm-g committed Oct 5, 2024
1 parent 4af85b0 commit d4c5d1f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ static tsi_result alts_tsi_handshaker_continue_handshaker_next(

struct alts_tsi_handshaker_continue_handshaker_next_args {
alts_tsi_handshaker* handshaker;
std::unique_ptr<unsigned char> received_bytes;
unsigned char* received_bytes;
size_t received_bytes_size;
tsi_handshaker_on_next_done_cb cb;
void* user_data;
Expand All @@ -509,13 +509,14 @@ static void alts_tsi_handshaker_create_channel(
grpc_channel_credentials_release(creds);
tsi_result continue_next_result =
alts_tsi_handshaker_continue_handshaker_next(
handshaker, next_args->received_bytes.get(),
handshaker, next_args->received_bytes,
next_args->received_bytes_size, next_args->cb, next_args->user_data,
next_args->error);
if (continue_next_result != TSI_OK) {
next_args->cb(continue_next_result, next_args->user_data, nullptr, 0,
nullptr);
}
gpr_free(next_args->received_bytes);
delete next_args;
}

Expand All @@ -532,6 +533,9 @@ static tsi_result handshaker_next(
if (received_bytes_size == 0) return TSI_INCOMPLETE_DATA;
alts_tsi_handshaker* handshaker =
reinterpret_cast<alts_tsi_handshaker*>(self);
if (!handshaker->is_client && received_bytes_size == 0) {
return TSI_INCOMPLETE_DATA;
}
{
grpc_core::MutexLock lock(&handshaker->mu);
if (handshaker->shutdown) {
Expand All @@ -548,9 +552,9 @@ static tsi_result handshaker_next(
args->received_bytes_size = received_bytes_size;
args->error = error;
if (received_bytes_size > 0) {
args->received_bytes = std::unique_ptr<unsigned char>(
static_cast<unsigned char*>(gpr_zalloc(received_bytes_size)));
memcpy(args->received_bytes.get(), received_bytes, received_bytes_size);
args->received_bytes =
static_cast<unsigned char*>(gpr_zalloc(received_bytes_size));
memcpy(args->received_bytes, received_bytes, received_bytes_size);
}
args->cb = cb;
args->user_data = user_data;
Expand Down

0 comments on commit d4c5d1f

Please sign in to comment.