diff -uprN a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc --- a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc 2021-10-20 04:14:40.000000000 +0800 +++ b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc 2024-10-10 10:28:04.853055800 +0800 @@ -375,6 +375,7 @@ tsi_result alts_create_frame_protector(c if (status != GRPC_STATUS_OK) { gpr_log(GPR_ERROR, "Failed to create ALTS crypters, %s.", error_details); gpr_free(error_details); + gpr_free(impl); return TSI_INTERNAL_ERROR; } /** diff -uprN a/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc b/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc --- a/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc 2021-10-20 04:14:40.000000000 +0800 +++ b/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc 2024-10-10 10:37:28.613055800 +0800 @@ -387,6 +387,19 @@ static void alts_test_do_round_trip_all( gpr_free(bit_array); } +TEST(AltsFrameProtectorTest, MemoryLeakTest) { + tsi_frame_protector* client_frame_protector = nullptr; + // Create a key with a wrong key length (off-by-one). + uint8_t* key = nullptr; + size_t key_length = kAes128GcmKeyLength - 1; + gsec_test_random_array(&key, key_length); + EXPECT_EQ(alts_create_frame_protector(key, key_length, /*is_client=*/true, + /*is_rekey=*/false, nullptr, + &client_frame_protector), + TSI_INTERNAL_ERROR); + gpr_free(key); +} + int main(int /*argc*/, char** /*argv*/) { alts_test_do_round_trip_vector_tests(); alts_test_do_round_trip_all(/*rekey=*/false);