Replace libc strdup usage with internal impl to restore musl compat. (#10811) (#10818)

Co-authored-by: Derek Perez <perezd@users.noreply.github.com>
pull/10819/head
Mike Kruskal 2 years ago committed by GitHub
parent 0d8ac768a1
commit 33bc6fb2a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      ruby/ext/google/protobuf_c/message.c

@ -1290,7 +1290,9 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
int n = upb_EnumDef_ValueCount(e); int n = upb_EnumDef_ValueCount(e);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
const upb_EnumValueDef* ev = upb_EnumDef_Value(e, 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); int32_t value = upb_EnumValueDef_Number(ev);
if (name[0] < 'A' || name[0] > 'Z') { if (name[0] < 'A' || name[0] > 'Z') {
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)); rb_define_const(mod, name, INT2NUM(value));
free(name); upb_Arena_Free(arena);
} }
rb_define_singleton_method(mod, "lookup", enum_lookup, 1); rb_define_singleton_method(mod, "lookup", enum_lookup, 1);

Loading…
Cancel
Save