diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 31d7dbbb44..fd83dc1c49 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1290,7 +1290,9 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { int n = upb_EnumDef_ValueCount(e); for (int i = 0; i < n; i++) { const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i); - char* name = strdup(upb_EnumValueDef_Name(ev)); + upb_Arena* arena = upb_Arena_New(); + const char* src_name = upb_EnumValueDef_Name(ev); + char* name = upb_strdup2(src_name, strlen(src_name), arena); int32_t value = upb_EnumValueDef_Number(ev); if (name[0] < 'A' || name[0] > 'Z') { if (name[0] >= 'a' && name[0] <= 'z') { @@ -1303,7 +1305,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { } } rb_define_const(mod, name, INT2NUM(value)); - free(name); + upb_Arena_Free(arena); } rb_define_singleton_method(mod, "lookup", enum_lookup, 1);