Skip to content

Commit

Permalink
[Ruby] replace strdup with gpr_strdup (grpc#34177)
Browse files Browse the repository at this point in the history
grpc 1.57.0 crashes win ruby and alpine due to no `strdup` in musl libc.
This diff replace `strdup` with `grp_strdup`

```
Thread 1 "ruby" received signal SIGSEGV, Segmentation fault.
0x00000000000a4596 in ?? ()
(gdb) bt
#0  0x00000000000a4596 in ?? ()
#1  0x00007ffff14e298c in grpc_rb_channel_create_in_process_add_args_hash_cb (key=<optimized out>, val=<optimized out>, args_obj=<optimized out>) at rb_channel_args.c:84
#2  0x00007ffff7c2b9ea in hash_ar_foreach_iter (error=0, argp=140737488344784, value=<optimized out>, key=<optimized out>) at hash.c:1341
```

fixes grpc#34044
closes grpc#27995
  • Loading branch information
alto-ruby authored Sep 19, 2023
1 parent 5236988 commit dfa040f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ruby/ext/grpc/rb_channel_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include "rb_grpc_imports.generated.h"

#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

static rb_data_type_t grpc_rb_channel_args_data_type = {
"grpc_channel_args",
Expand Down Expand Up @@ -74,14 +76,14 @@ static int grpc_rb_channel_create_in_process_add_args_hash_cb(VALUE key,
case T_SYMBOL:
args->args[args->num_args - 1].type = GRPC_ARG_STRING;
args->args[args->num_args - 1].value.string =
strdup(rb_id2name(SYM2ID(val)));
gpr_strdup(rb_id2name(SYM2ID(val)));
--args->num_args;
return ST_CONTINUE;

case T_STRING:
args->args[args->num_args - 1].type = GRPC_ARG_STRING;
args->args[args->num_args - 1].value.string =
strdup(StringValueCStr(val));
gpr_strdup(StringValueCStr(val));
--args->num_args;
return ST_CONTINUE;

Expand Down Expand Up @@ -162,8 +164,8 @@ void grpc_rb_channel_args_destroy(grpc_channel_args* args) {
if (args->args == NULL) return;
for (int i = 0; i < args->num_args; i++) {
if (args->args[i].type == GRPC_ARG_STRING) {
// we own string pointers, which were created with strdup
free(args->args[i].value.string);
// we own string pointers, which were created with gpr_strdup
gpr_free(args->args[i].value.string);
}
}
xfree(args->args);
Expand Down

0 comments on commit dfa040f

Please sign in to comment.