Re: [PATCH 1/4] bisect--helper: `bisect_clean_state` shell function in C
- From
Pranit Bauva <pranit.bauva@gmail.com>
- Date
- Jun 8, 2016, 18:04 UTC
- Message-ID
- <CAFZEwPO+E7zzPoBnEbfZtW1RfXWzTbzAGzE_WXW8BNfhTb+urw@mail.gmail.com>
- In-Reply-To
- <CAPig+cQ5z+-59BCjPXNaSQWkSyTt56yAnRo49Lba6_wjkWRp-w@mail.gmail.com>
Hey Eric,
On Wed, Jun 8, 2016 at 11:29 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 45 quoted lines
> On Wed, Jun 8, 2016 at 5:41 AM, Christian Couder
> <christian.couder@gmail.com> wrote:
>> On Wed, Jun 8, 2016 at 10:02 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>>> On Wed, Jun 8, 2016 at 3:46 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
>>>> On Wed, Jun 8, 2016 at 4:01 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>>>>> On Tue, Jun 7, 2016 at 4:54 PM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
>>>>>> + struct string_list *refs = cb_data;
>>>>>> + char *ref = xstrfmt("refs/bisect/%s", refname);
>>>>>
>>>>> Here you're allocating a string...
>>>>>
>>>>>> + string_list_append(refs, ref);
>>>>>> + return 0;
>>>>>> +}
>>>>>> +
>>>>>> +int bisect_clean_state(void)
>>>>>> +{
>>>>>> + int result = 0;
>>>>>> + struct string_list refs_for_removal = STRING_LIST_INIT_DUP;
>>>>>> + for_each_ref_in("refs/bisect/", mark_for_removal, (void *) &refs_for_removal);
>>>>>
>>>>> ...and the allocated string gets inserted into a string_list which
>>>>> itself duplicates the string (STRING_LIST_INIT_DUP), so this is
>>>>> leaking the string you created with xstrfmt(), isn't it?
>>>>
>>>> Yes nice catch. I would prefer using the string_list with
>>>> STRING_LIST_INIT_DUP and free the ref.
>>>
>>> That's unnecessarily wasteful. Better would be to to use STRING_LIST_INIT_NODUP.
>>
>> In this case it is not possible to append "BISECT_HEAD" to
>> 'refs_for_removal' before calling delete_refs() like this:
>>
>> + for_each_ref_in("refs/bisect/", mark_for_removal, (void *)
>> &refs_for_removal);
>> + string_list_append(&refs_for_removal, "BISECT_HEAD");
>> + result = delete_refs(&refs_for_removal);
>> + string_list_clear(&refs_for_removal, 0);
>>
>> And I think it's better to delete all the refs in the same call to
>> delete_refs().
>
> string_list_append(&..., xstrdup("BISECT_HEAD"));
>
> perhaps?Seems reasonable!
Regards, Pranit Bauva