Fixed memory bug: properly root repeated/map field when assigning. #8639
Previously the protobuf extension would not properly root memory from a repeated field or map when assigning to a message field (see the attached test case). If there is no direct reference to the repeated field from Ruby, this will result in a memory error if there is a GC and the repeated field is subsequently accessed (for example, in
The fix is to do the appropriate
The the new test case does not actually crash on my machine, but it does trigger a Valgrind error that I can confirm is fixed by the code in this PR. In the future we should make sure that our CI tests are running tests under Valgrind so we can catch future memory errors of this kind.
Also added an explicit check that
Previously the protobuf extension would not properly root memory from a repeated field or map when assigning to a message field (see the attached test case). This could cause crashes if the repeated field is subsequently accessed.
Due to protocolbuffers/protobuf#8559, google-protobuf v3.15.8 can seg fault in the FindCommits RPC call if the options hash is garbage collected before gRPC encodes the message. This was fixed in google-protobuf v3.17.1 via protocolbuffers/protobuf#8639. Unfortunately, pg_query has a hard dependency on google-protobuf v3.15.x. This was bumped in pganalyze/pg_query#212, but an official version has not yet been tagged. In addition, pganalyze/pg_query#213 would relax the dependency so that google-protobuf can be upgraded without having to update pg_query. Until pg_query releases a new version, we use our fork to ensure this seg fault cannot happen. Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/330998 Changelog: fixed