git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jeff King <peff@peff.net>
Date
Sep 29, 2017, 07:23 UTC
Message-ID
<20170929072354.fw4eclt56dmfj4a5@sigill.intra.peff.net>
In-Reply-To
<CAP8UFD13obkLWyuCGUpFxryr8DWfQ8W4JNn04ajO50PvF0SnXQ@mail.gmail.com>
On Fri, Sep 29, 2017 at 09:18:11AM +0200, Christian Couder wrote:
Show 45 quoted lines
> On Fri, Sep 29, 2017 at 12:42 AM, Jeff King <peff@peff.net> 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.

Check reprepare_packed_git(). It unsets the run_once flag, and then calls prepare_packed_git() again.

-Peff
Previous: Christian CouderNext: Christian Couder
Message 11 of 26 in “[Outreachy] cleanup: use list.h in mru.h and mru.c”
  1. [Outreachy] cleanup: use list.h in mru.h and mru.cОля Тележная, Sep 27, 2017
  2. Christian CouderSep 27, 2017
  3. mru: use double-linked list from list.hOlga Telezhnaya, Sep 28, 2017
  4. Junio C HamanoSep 28, 2017
  5. Jeff KingSep 28, 2017
  6. Junio C HamanoSep 28, 2017
  7. Jeff KingSep 28, 2017
  8. Jeff KingSep 28, 2017
  9. Jeff KingSep 28, 2017
  10. Christian CouderSep 29, 2017
  11. Jeff KingSep 29, 2017
  12. Christian CouderSep 29, 2017
  13. Оля ТележнаяSep 29, 2017
  14. Оля ТележнаяSep 29, 2017
  15. Jeff KingSep 29, 2017
  16. Оля ТележнаяSep 30, 2017
  17. Jeff KingOct 2, 2017
  18. Jeff KingSep 29, 2017
  19. Junio C HamanoSep 30, 2017
  20. mru: use double-linked list from list.hOlga Telezhnaya, Sep 30, 2017
  21. Jeff KingOct 2, 2017
  22. Оля ТележнаяOct 2, 2017
  23. Jeff KingOct 3, 2017
  24. Junio C HamanoNov 8, 2017
  25. Jeff KingNov 8, 2017
  26. Оля ТележнаяNov 10, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.