From 1ed726c6f5ad5e08257986930bf732713aecdcf7 Mon Sep 17 00:00:00 2001 From: Hongyu Chen Date: Thu, 5 Feb 2015 15:49:09 -0800 Subject: [PATCH] More update on dup_annotation_list following review comments. --- src/core/statistics/census_tracing.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/core/statistics/census_tracing.c b/src/core/statistics/census_tracing.c index 4c030152e6e..bcd0ee4787b 100644 --- a/src/core/statistics/census_tracing.c +++ b/src/core/statistics/census_tracing.c @@ -193,20 +193,14 @@ const char* census_get_trace_method_name(const trace_obj* trace) { } static trace_annotation* dup_annotation_chain(trace_annotation* from) { - trace_annotation *to = NULL, *prev = NULL; + trace_annotation *ret = NULL; + trace_annotation **to = &ret; for (; from != NULL; from = from->next) { - trace_annotation* tmp = gpr_malloc(sizeof(trace_annotation)); - memcpy(tmp, from, sizeof(trace_annotation)); - tmp->next = NULL; - if (to == NULL) { - to = tmp; - prev = to; - } else { - prev->next = tmp; - prev = tmp; - } + *to = gpr_malloc(sizeof(trace_annotation)); + memcpy(*to, from, sizeof(trace_annotation)); + to = &(*to)->next; } - return to; + return ret; } static trace_obj* trace_obj_dup(trace_obj* from) {