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: 652947042pull/17492/head
parent
8b7c84b488
commit
f712ca5d1c
4 changed files with 34 additions and 14 deletions
Loading…
Reference in new issue