Skip to content

Commit 8ea7ed2

Browse files
abhishekkumar2718gitster
authored andcommitted
oidmap: make oidmap_free independent of struct layout
c8e424c (hashmap: introduce hashmap_free_entries, 2019-10-06) introduced hashmap_free_entries(), which can free any struct pointer, regardless of the hashmap_entry field offset. oidmap does not make use of this flexibilty, hardcoding the offset to zero instead. Let's fix this by passing struct type and member to hashmap_free_entries(). Additionally, remove an erroneous semi-colon at the end of hashmap_free_entries() macro. Signed-off-by: Abhishek Kumar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c8e424c commit 8ea7ed2

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

hashmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void hashmap_free_(struct hashmap *map, ssize_t offset);
245245
* where @member is the hashmap_entry struct used to associate with @map
246246
*/
247247
#define hashmap_free_entries(map, type, member) \
248-
hashmap_free_(map, offsetof(type, member));
248+
hashmap_free_(map, offsetof(type, member))
249249

250250
/* hashmap_entry functions */
251251

oidmap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ void oidmap_free(struct oidmap *map, int free_entries)
2626
if (!map)
2727
return;
2828

29-
/* TODO: make oidmap itself not depend on struct layouts */
30-
hashmap_free_(&map->map, free_entries ? 0 : -1);
29+
if (free_entries)
30+
hashmap_free_entries(&map->map, struct oidmap_entry, internal_entry);
31+
else
32+
hashmap_free(&map->map);
3133
}
3234

3335
void *oidmap_get(const struct oidmap *map, const struct object_id *key)

0 commit comments

Comments
 (0)