From 33bc6fb2a4a907b322fa7b3abcebdc6bb69ac4c4 Mon Sep 17 00:00:00 2001 From: Mike Kruskal <62662355+mkruskal-google@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:26:51 -0700 Subject: [PATCH] Replace libc strdup usage with internal impl to restore musl compat. (#10811) (#10818) Co-authored-by: Derek Perez --- ruby/ext/google/protobuf_c/message.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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);