Commit

95d48952cc66b299554ebd90aada5c3fbc2a6e7d

repository: make repo_clear() idempotent

Calling repo_clear() twice in a row will segfault because the second
call will invoke parse_object_pool_clear() on a NULL pointer. This is
not usually a big deal, but we can make some error cleanup a little
simpler if callers do not need to worry about invoking it twice.

We can fix it by catching the NULL case. The rest of repo_clear()
appears to be idempotent.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King <peff@peff.net> · 2026-09-02 05:55 UTC · committed by Junio C Hamano

Browse files
1 file changed, +2 −1
modified repository.c
@@ -384,7 +384,8 @@ void repo_clear(struct repository *repo)
384 384 odb_free(repo->objects);
385 385 repo->objects = NULL;
386 386
387 - parsed_object_pool_clear(repo->parsed_objects);
387 + if (repo->parsed_objects)
388 + parsed_object_pool_clear(repo->parsed_objects);
388 389 FREE_AND_NULL(repo->parsed_objects);
389 390
390 391 repo_settings_clear(repo);