Skip to content

Commit a98ea50

Browse files
Seyi007gitster
authored andcommitted
builtin/rev-list: migrate missing_objects cleanup to oidmap_clear_with_free()
As part of the conversion away from oidmap_clear(), switch the missing_objects map to use oidmap_clear_with_free(). missing_objects stores struct missing_objects_map_entry instances, which own an xstrdup()'d path string in addition to the container struct itself. Previously, rev-list manually freed entry->path before calling oidmap_clear(&missing_objects, true). Introduce a dedicated free callback and pass it to oidmap_clear_with_free(), consolidating entry teardown into a single place and making cleanup semantics explicit. Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a06a725 commit a98ea50

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

builtin/rev-list.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,19 @@ static int arg_print_omitted; /* print objects omitted by filter */
8888

8989
struct missing_objects_map_entry {
9090
struct oidmap_entry entry;
91-
const char *path;
91+
char *path;
9292
unsigned type;
9393
};
94+
95+
static void missing_objects_map_entry_free(void *e)
96+
{
97+
struct missing_objects_map_entry *entry =
98+
container_of(e, struct missing_objects_map_entry, entry);
99+
100+
free(entry->path);
101+
free(entry);
102+
}
103+
94104
static struct oidmap missing_objects;
95105
enum missing_action {
96106
MA_ERROR = 0, /* fail if any missing objects are encountered */
@@ -935,10 +945,9 @@ int cmd_rev_list(int argc,
935945
while ((entry = oidmap_iter_next(&iter))) {
936946
print_missing_object(entry, arg_missing_action ==
937947
MA_PRINT_INFO);
938-
free((void *)entry->path);
939948
}
940949

941-
oidmap_clear(&missing_objects, true);
950+
oidmap_clear_with_free(&missing_objects, missing_objects_map_entry_free);
942951
}
943952

944953
stop_progress(&progress);

0 commit comments

Comments
 (0)