Skip to content

Conversation

@Mifacopy
Copy link

Summary

This change backports/adapts the behavior from nanopb commit 4fe23595732b6f1254cfc11a9b8d6da900b55b0c. It fixes a memory leak in the decode path when using oneof fields together with PB_ENABLE_MALLOC.

Problem

When:

  • PB_ENABLE_MALLOC is enabled,
  • A message contains a oneof field,
  • The oneof contains a static submessage with pointer fields,
  • Decoded data contains two values for that submessage,

the previous logic in pb_release_union_field() did not free the old submessage correctly, and decode_static_field() then memsets the uninitialized memory regardless of whether it should be reset or not, leading to a leak.

Fix

Adjust the logic so that memset() is only performed when the which_field tag is different. This ensures previously allocated memory is released correctly and no leak occurs.

Impact

  • Addresses a specific leak scenario during decoding.
  • No other behavioral changes intended.

Reference

  • Upstream commit: 4fe23595732b6f1254cfc11a9b8d6da900b55b0c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant