From: Patrick Steinhardt Date: Thu, 18 Jun 2026 06:54:38 GMT Subject: Re: [PATCH v2 4/8] refs: unregister reference stores from "chdir_notify" Message-ID: In-Reply-To: On Wed, Jun 17, 2026 at 01:02:23PM -0500, Justin Tobler wrote: > On 26/06/15 03:56PM, Patrick Steinhardt wrote: > > When creating reference stores we register them with the "chdir_notify" > > subsystem. This is required because some of the paths we track may be > > relative paths, so we have to reparent them in case the current working > > directory changes. > > > > But while we register the reference stores, we never unregister them. > > This can have multiple outcomes: > > > > - For a repository's main reference database we essentially keep the > > pointer alive. We never free that database, either, and our leak > > checker doesn't notice because it's still registered. > > > > - For submodule and worktree reference databases we do eventually free > > them in `repo_clear()`, so we may keep pointers to free'd memory > > registered. We never notice though as we don't tend to chdir around > > in the middle of the process. > > > > We never noticed either of these symptoms, but they are obviously bad. > > > > Partially fix those issues by unregistering the reference stores when > > releasing them. The leak of the main reference database will be fixed in > > a subsequent commit. > > > > Note that this requires us to use `chdir_notify_register()` instead of > > `chdir_notify_reparent()`, as there is no infrastructure to unregister the > > latter. It ultimately doesn't matter much though: in a subsequent commit > > we'll drop this infrastructure completely. We merely require this step > > here so that we can fix the memory leaks ahead of time. > > Since this version of the series dropped the last patch which stopped > using `chdir_notify_reparent()`, does the log message here need to be > updated? True, will do. Patrick