Skip to content

Commit

Permalink
Merge pull request #9150 from Shopify/pz-message-encode-mem-leak
Browse files Browse the repository at this point in the history
[Ruby] Fix memory leak in MessageClass.encode
  • Loading branch information
deannagarcia committed Oct 26, 2021
2 parents e350ef8 + 3a18299 commit 247649c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ruby/ext/google/protobuf_c/message.c
Expand Up @@ -1012,14 +1012,15 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
*/
static VALUE Message_encode(VALUE klass, VALUE msg_rb) {
Message* msg = ruby_to_Message(msg_rb);
upb_arena *arena = upb_arena_new();
const char *data;
size_t size;

if (CLASS_OF(msg_rb) != klass) {
rb_raise(rb_eArgError, "Message of wrong type.");
}

upb_arena *arena = upb_arena_new();

data = upb_encode(msg->msg, upb_msgdef_layout(msg->msgdef), arena,
&size);

Expand Down

0 comments on commit 247649c

Please sign in to comment.