diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 8782584a1a..b2f4f79901 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2859,7 +2859,14 @@ UPB_INLINE bool _upb_Message_SetExtensionField( UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg, const upb_MiniTable* m) { UPB_ASSERT(!upb_Message_IsFrozen(msg)); + upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); memset(msg, 0, m->UPB_PRIVATE(size)); + if (in) { + // Reset the internal buffer to empty. + in->unknown_end = sizeof(upb_Message_Internal); + in->ext_begin = in->size; + UPB_PRIVATE(_upb_Message_SetInternal)(msg, in); + } } UPB_API_INLINE void upb_Message_ClearBaseField(struct upb_Message* msg, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 9e91530e08..379fad459a 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2861,7 +2861,14 @@ UPB_INLINE bool _upb_Message_SetExtensionField( UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg, const upb_MiniTable* m) { UPB_ASSERT(!upb_Message_IsFrozen(msg)); + upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg); memset(msg, 0, m->UPB_PRIVATE(size)); + if (in) { + // Reset the internal buffer to empty. + in->unknown_end = sizeof(upb_Message_Internal); + in->ext_begin = in->size; + UPB_PRIVATE(_upb_Message_SetInternal)(msg, in); + } } UPB_API_INLINE void upb_Message_ClearBaseField(struct upb_Message* msg,