Skip to content

Commit bbf4b4b

Browse files
Seyi007gitster
authored andcommitted
odb: use oidmap_clear_with_free() to release replace_map entries
Replace the direct oidmap_clear() call in odb_free() with oidmap_clear_with_free(), and introduce a free_replace_map_entry() helper to properly free each struct replace_object stored in the map. This centralizes cleanup logic and ensures entries are released correctly via a dedicated callback. Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6ff1507 commit bbf4b4b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

odb.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "object-file-convert.h"
1515
#include "object-file.h"
1616
#include "odb.h"
17+
#include "oidmap.h"
1718
#include "packfile.h"
1819
#include "path.h"
1920
#include "promisor-remote.h"
@@ -1089,6 +1090,13 @@ void odb_close(struct object_database *o)
10891090
close_commit_graph(o);
10901091
}
10911092

1093+
static void free_replace_map_entry(void *e)
1094+
{
1095+
struct replace_object *entry =
1096+
container_of(e, struct replace_object, original);
1097+
free(entry);
1098+
}
1099+
10921100
static void odb_free_sources(struct object_database *o)
10931101
{
10941102
while (o->sources) {
@@ -1109,7 +1117,8 @@ void odb_free(struct object_database *o)
11091117

11101118
free(o->alternate_db);
11111119

1112-
oidmap_clear(&o->replace_map, 1);
1120+
if (o->replace_map_initialized)
1121+
oidmap_clear_with_free(&o->replace_map, free_replace_map_entry);
11131122
pthread_mutex_destroy(&o->replace_mutex);
11141123

11151124
odb_close(o);

0 commit comments

Comments
 (0)