Now that get_short_ref() always return an malloced string, consolidate to one xstrcpy() call. Signed-off-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx> --- Also an Acked-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx> for Jeffs patch. builtin-for-each-ref.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-) diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index 4aaf75c..108c128 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -596,13 +596,13 @@ static char *get_short_ref(const char *ref) } } - /* bail out if there are no rules */ - if (!nr_rules) - return xstrdup(ref); - /* buffer for scanf result, at most ref must fit */ short_name = xstrdup(ref); + /* bail out if there are no rules */ + if (!nr_rules) + return short_name; + /* skip first rule, it will always match */ for (i = nr_rules - 1; i > 0 ; --i) { int j; @@ -641,8 +641,7 @@ static char *get_short_ref(const char *ref) return short_name; } - free(short_name); - return xstrdup(ref); + return strcpy(short_name, ref); } -- tg: (e9786d7..) bw/ammend-jk/refactor-get_short_ref (depends on: jk/refactor-get_short_ref) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html