[PATCH 2/2] ui-stats: do not duplicate string

John Keeping john at keeping.me.uk
Mon Oct 12 11:11:03 CEST 2015


On Mon, Oct 12, 2015 at 10:59:35AM +0200, Christian Hesse wrote:
> From: Christian Hesse <mail at eworm.de>
> 
> string_list_insert() expects (const char*), so no need to duplicate and
> free the string.
> 
> Signed-off-by: Christian Hesse <mail at eworm.de>
> ---
>  ui-stats.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)

This has the same problem as the previous patch.

> diff --git a/ui-stats.c b/ui-stats.c
> index 02335e7..26473de 100644
> --- a/ui-stats.c
> +++ b/ui-stats.c
> @@ -171,24 +171,19 @@ static void add_commit(struct string_list *authors, struct commit *commit,
>  	struct string_list_item *author, *item;
>  	struct authorstat *authorstat;
>  	struct string_list *items;
> -	char *tmp;
>  	struct tm *date;
>  	time_t t;
>  
>  	info = cgit_parse_commit(commit);
> -	tmp = xstrdup(info->author);
> -	author = string_list_insert(authors, tmp);
> +	author = string_list_insert(authors, info->author);
>  	if (!author->util)
>  		author->util = xcalloc(1, sizeof(struct authorstat));
> -	free(tmp);
>  	authorstat = author->util;
>  	items = &authorstat->list;
>  	t = info->committer_date;
>  	date = gmtime(&t);
>  	period->trunc(date);
> -	tmp = xstrdup(period->pretty(date));
> -	item = string_list_insert(items, tmp);
> -	free(tmp);
> +	item = string_list_insert(items, period->pretty(date));
>  	item->util++;
>  	authorstat->total++;
>  	cgit_free_commitinfo(info);
> -- 
> 2.6.1


More information about the CGit mailing list