diff --git a/src/core/lib/channel/channel_args.c b/src/core/lib/channel/channel_args.c index 28d2d78d00f81e015037f41c98be72d0022c7064..97c40e8481058b3e6957c036d4ee5104c9f059c8 100644 --- a/src/core/lib/channel/channel_args.c +++ b/src/core/lib/channel/channel_args.c @@ -74,7 +74,8 @@ grpc_channel_args *grpc_channel_args_copy_and_add(const grpc_channel_args *src, return dst; } dst->num_args = src_num_args + num_to_add; - dst->args = gpr_malloc(sizeof(grpc_arg) * dst->num_args); + dst->args = + dst->num_args ? gpr_malloc(sizeof(grpc_arg) * dst->num_args) : NULL; for (i = 0; i < src_num_args; i++) { dst->args[i] = copy_arg(&src->args[i]); } diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index ad8ee8c7a99ef3dc90fad5866e0c55a18c8296d8..e3b54ac012e0db6d90119a06c34c3a432346f69e 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -251,7 +251,9 @@ static void channel_broadcaster_init(grpc_server *s, channel_broadcaster *cb) { count++; } cb->num_channels = count; - cb->channels = gpr_malloc(sizeof(*cb->channels) * cb->num_channels); + cb->channels = cb->num_channels + ? gpr_malloc(sizeof(*cb->channels) * cb->num_channels) + : NULL; count = 0; for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) { cb->channels[count++] = c->channel;