Re: [GSoC14][RFC] Proposal Draft: Refactor tempfile handling
- From
Brian Gesiak <modocache@gmail.com>
- Date
- Mar 12, 2014, 12:26 UTC
- Message-ID
- <CAN7MxmXzowHjPFKS_+Dw8n8GUX7ooqTXW6MAGpNLA-VxnFY9uQ@mail.gmail.com>
- In-Reply-To
- <20140311180559.GB28154@sigill.intra.peff.net>
Show 5 quoted lines
> Currently the linked list of lockfiles only grows, never shrinks. Once > an object has been linked into the list, there is no way to remove it > again even after the lock has been released. So if a lock needs to be > created dynamically at a random place in the code, its memory is > unavoidably leaked.
Ah yes, I see. I think a good example is config.git_config_set_multivar_in_file, which even contains a comment detailing the problem: "Since lockfile.c keeps a linked list of all created lock_file structures, it isn't safe to free(lock). It's better to just leave it hanging around."
Show 5 quoted lines
> But I have a feeling that if we want to use a similar mechanism to > handle all temporary files (of which there can be more), then it would > be a good idea to lift this limitation. It will require some care, > though, to make sure that record removal is done in a way that is > threadsafe and safe in the event of all expected kinds of process death.
It sounds like a threadsafe linked-list with an interface to manually remove elements from the list is the solution here; does that sound reasonable? Ensuring thread safety without sacrificing readability is probably more difficult than it sounds, but I don't think it's impossible.
I'll add some more details on this to my proposal[1]. Thank you!
- Brian Gesiak
[1] https://www.google-melange.com/gsoc/proposal/review/student/google/gsoc2014/modocache/5629499534213120