xref: /third_party/grpc/fix-memory-leak.patch (revision 82744510)
1diff -uprN a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc
2--- a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc	2021-10-20 04:14:40.000000000 +0800
3+++ b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc	2024-10-10 10:28:04.853055800 +0800
4@@ -375,6 +375,7 @@ tsi_result alts_create_frame_protector(c
5   if (status != GRPC_STATUS_OK) {
6     gpr_log(GPR_ERROR, "Failed to create ALTS crypters, %s.", error_details);
7     gpr_free(error_details);
8+    gpr_free(impl);
9     return TSI_INTERNAL_ERROR;
10   }
11   /**
12diff -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
13--- a/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc	2021-10-20 04:14:40.000000000 +0800
14+++ b/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc	2024-10-10 10:37:28.613055800 +0800
15@@ -387,6 +387,19 @@ static void alts_test_do_round_trip_all(
16   gpr_free(bit_array);
17 }
18 
19+TEST(AltsFrameProtectorTest, MemoryLeakTest) {
20+  tsi_frame_protector* client_frame_protector = nullptr;
21+  // Create a key with a wrong key length (off-by-one).
22+  uint8_t* key = nullptr;
23+  size_t key_length = kAes128GcmKeyLength - 1;
24+  gsec_test_random_array(&key, key_length);
25+  EXPECT_EQ(alts_create_frame_protector(key, key_length, /*is_client=*/true,
26+                                        /*is_rekey=*/false, nullptr,
27+                                        &client_frame_protector),
28+            TSI_INTERNAL_ERROR);
29+  gpr_free(key);
30+}
31+
32 int main(int /*argc*/, char** /*argv*/) {
33   alts_test_do_round_trip_vector_tests();
34   alts_test_do_round_trip_all(/*rekey=*/false);
35