dep-protobuf/rust/cpp_kernel
Adam Cozzette f712ca5d1c Rust protobuf: fix memory leaks
Our ASAN test runs have not had the heap checker enabled, so this has allowed a
few memory leaks to slip in. This CL fixes all of them so that we can turn on
the heap checker.

The first one takes place whenever we add an entry into a string-valued map
using the C++ kernel. The problem is that `InnerProtoString::into_raw()` gives
up ownership of the raw `std::string` pointer it holds, but then we never
delete that pointer. This CL fixes the problem by deleting the pointer in C++
right after we perform the map insertion. To simplify things, I created a
`MakeCleanup()` helper function that we always call in our map insertion
thunks, but it's a no-op in the cases where we don't need to free anything.

There were a couple similar memory leaks related to repeated field accessors in
the C++ kernel, and those were simple to fix just by adding the necessary
`delete` call.

Finally, there were two benign memory leaks in the upb kernel involving global
variables used for empty repeated fields and maps. It turned out that we did
not need to use `Box` at all here, so removing that simplified things and fixed
the leaks.

PiperOrigin-RevId: 652947042
2024-07-16 13:01:48 -07:00
..
BUILD Split up cpp_api.h/.cc into smaller units. 2024-06-28 06:54:35 -07:00
debug.cc Enable MessageLite::DebugString to use Message::DebugString where possible. 2024-07-03 09:37:37 -07:00
debug.h Enable MessageLite::DebugString to use Message::DebugString where possible. 2024-07-03 09:37:37 -07:00
map.cc Migrate Repeated::{push, set} and Map::insert to use the IntoProxied trait. 2024-07-09 04:47:00 -07:00
map.h Rust protobuf: fix memory leaks 2024-07-16 13:01:48 -07:00
repeated.cc Rust protobuf: fix memory leaks 2024-07-16 13:01:48 -07:00
rust_alloc_for_cpp_api.h Change to proto2_rust C prefix and proto2::rust C++ namespace 2024-07-02 11:44:17 -07:00
rust_alloc_for_cpp_api.rs Change to proto2_rust C prefix and proto2::rust C++ namespace 2024-07-02 11:44:17 -07:00
serialized_data.h Change to proto2_rust C prefix and proto2::rust C++ namespace 2024-07-02 11:44:17 -07:00
strings.cc Use a std::string as the backing string & bytes type in the C++ kernel. This will allow us to move a ProtoString/Bytes to a message accessor without copying. This change only touches the C++ kernel, as the UPB kernel already uses the native arena-allocated UPB string type for ProtoString/Bytes. 2024-07-03 02:59:06 -07:00
strings.h Use a std::string as the backing string & bytes type in the C++ kernel. This will allow us to move a ProtoString/Bytes to a message accessor without copying. This change only touches the C++ kernel, as the UPB kernel already uses the native arena-allocated UPB string type for ProtoString/Bytes. 2024-07-03 02:59:06 -07:00