Fix memory leak in MessageClass.encode
If the line above raises an exception, the upb_arena is lost and memory is leaked.
This commit is contained in:
parent
e58469bdbe
commit
b2ac7ced50
@ -1012,7 +1012,6 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|||||||
*/
|
*/
|
||||||
static VALUE Message_encode(VALUE klass, VALUE msg_rb) {
|
static VALUE Message_encode(VALUE klass, VALUE msg_rb) {
|
||||||
Message* msg = ruby_to_Message(msg_rb);
|
Message* msg = ruby_to_Message(msg_rb);
|
||||||
upb_arena *arena = upb_arena_new();
|
|
||||||
const char *data;
|
const char *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
@ -1020,6 +1019,8 @@ static VALUE Message_encode(VALUE klass, VALUE msg_rb) {
|
|||||||
rb_raise(rb_eArgError, "Message of wrong type.");
|
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,
|
data = upb_encode(msg->msg, upb_msgdef_layout(msg->msgdef), arena,
|
||||||
&size);
|
&size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user