mbox series

[v3,0/2] setup: fix memory leaks with `struct repository_format`

Message ID cover.1548186510.git.martin.agren@gmail.com (mailing list archive)
Headers show
Series setup: fix memory leaks with `struct repository_format` | expand

Message

Martin Ågren Jan. 22, 2019, 9:45 p.m. UTC
On Tue, 22 Jan 2019 at 14:34, Martin Ågren <martin.agren@gmail.com> wrote:
>
> On Tue, 22 Jan 2019 at 08:07, Jeff King <peff@peff.net> wrote:
>
> > For the record, I can live with it either way. There are so many funky
> > little setup corner cases in the code already, and we don't even really
> > have a real-world case to dissect at this point. So the right thing may
> > also just be to finish this patch series as quickly as possible and move
> > on to something more useful. :)
>
> I rebased the "something like this?" into this series yesterday and I
> think the end result is better, but also that the way there is clearer,
> mostly because this patch is then gone. I wanted to double-check it
> tonight and submit it. I'll do that tonight.

Here's that reroll. I now reset the entire struct in the error path of
`clear_...()`. Thus, the user that is reading `repo_fmt.hash_algo`
despite not being supposed to, can keep reading it, now knowing that the
value has a default value.

I also expanded on the documentation a little to point out that we'll
reset to the default struct state if we don't find any
"core.repositoryformatversion".

Martin

Martin Ågren (2):
  setup: free old value before setting `work_tree`
  setup: fix memory leaks with `struct repository_format`

 cache.h           | 27 ++++++++++++++++++++++++---
 builtin/init-db.c |  3 ++-
 repository.c      |  3 ++-
 setup.c           | 33 +++++++++++++++++++++------------
 worktree.c        |  4 +++-
 5 files changed, 52 insertions(+), 18 deletions(-)