Re: [PATCH 5/7] grep: allocate subrepos on heap

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

 



> > +static struct repository **repos_to_free;
> > +static size_t repos_to_free_nr, repos_to_free_alloc;
> 
> One thing I was curious about was whether it would make more sense to
> use an existing utility library in Git to handle this. But I think we
> kind of are, since ALLOC_GROW is used, so this is idiomatic for Git
> project. Ok, fine, I guess this is life at C ;)

Yeah, this *is* the utility library :-)

> > +static void free_repos(void)
> > +{
> > +	int i;
> > +
> > +	for (i = 0; i < repos_to_free_nr; i++) {
> > +		repo_clear(repos_to_free[i]);
> > +		free(repos_to_free[i]);
> > +	}
> > +	free(repos_to_free);
> > +}
> 
> Should repos_to_free_nr be reset here? I guess it doesn't make sense to,
> since we'd be trying to use-after-free the initial repos_to_free head
> pointer too if we wanted to reuse this array.

Hmm...I guess that if I'm going through the trouble of clearing the
repos instead of just letting all the memory be collected at the end of
a process, I should also reset _nr and _alloc. I'll make that change.



[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