Re: [PATCH 5/5] branch: fix branch_checked_out() leaks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Derrick Stolee <derrickstolee@xxxxxxxxxx> writes:

>  	while (worktrees[i]) {
> +		char *old;
>  		struct wt_status_state state = { 0 };
>  		struct worktree *wt = worktrees[i++];
>  
>  		if (wt->is_bare)
>  			continue;
>  
> -		if (wt->head_ref)
> -			strmap_put(&current_checked_out_branches,
> -				   wt->head_ref,
> -				   xstrdup(wt->path));
> +		if (wt->head_ref) {
> +			old = strmap_put(&current_checked_out_branches,
> +					 wt->head_ref,
> +					 xstrdup(wt->path));
> +			free(old);
> +		}

While it is equivalent to

			free(strmap_put(&current_checked_out_branches,
                        		wt->head_ref,
					xstrdup(wt->path)));

writing the "put the new one" and "discard the old one (if exists)"
as separate steps like the above does make it easier to follow, at
least to me.

Thanks.  Will queue.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux