Re: [PATCH Outreachy] mru: use double-linked list from list.h

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

 



On Fri, Sep 29, 2017 at 12:42 AM, Jeff King <peff@xxxxxxxx> wrote:
> On Thu, Sep 28, 2017 at 08:38:39AM +0000, Olga Telezhnaya wrote:
>
>> diff --git a/packfile.c b/packfile.c
>> index f69a5c8d607af..ae3b0b2e9c09a 100644
>> --- a/packfile.c
>> +++ b/packfile.c
>> @@ -876,6 +876,7 @@ void prepare_packed_git(void)
>>       for (alt = alt_odb_list; alt; alt = alt->next)
>>               prepare_packed_git_one(alt->path, 0);
>>       rearrange_packed_git();
>> +     INIT_LIST_HEAD(&packed_git_mru.list);
>>       prepare_packed_git_mru();
>>       prepare_packed_git_run_once = 1;
>>  }
>
> I was thinking on this hunk a bit more, and I think it's not quite
> right.
>
> The prepare_packed_git_mru() function will clear the mru list and then
> re-add each item from the packed_git list. But by calling
> INIT_LIST_HEAD() here, we're effectively clearing the packed_git_mru
> list, and we end up leaking whatever was on the list before.

The current code is:

static int prepare_packed_git_run_once = 0;
void prepare_packed_git(void)
{
    struct alternate_object_database *alt;

    if (prepare_packed_git_run_once)
        return;
    prepare_packed_git_one(get_object_directory(), 1);
    prepare_alt_odb();
    for (alt = alt_odb_list; alt; alt = alt->next)
        prepare_packed_git_one(alt->path, 0);
    rearrange_packed_git();
    prepare_packed_git_mru();
    prepare_packed_git_run_once = 1;
}

As we use the "prepare_packed_git_run_once" static, this function will
only be called only once when packed_git_mru has not yet been
initialized, so there will be no leak.



[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