1 #include <stdlib.h>
2
3 struct hashmap_entry {
4 struct hashmap_entry *next;
5 unsigned int hash;
6 };
7
8 struct strbuf {
9 size_t alloc;
10 size_t len;
11 char *buf;
12 };
13
14 struct oid2strbuf {
15 struct hashmap_entry ent; /* must be the first member! */
16 unsigned char key[21];
17 struct strbuf *value;
18 };
19
20
21 struct hashmap_iter {
22 struct hashmap *map;
23 struct hashmap_entry *next;
24 unsigned int tablepos;
25 };
26
27 struct hashmap {
28 struct hashmap_entry **table;
29 // hashmap_cmp_fn cmpfn;
30 unsigned int size, tablesize, grow_at, shrink_at;
31 unsigned disallow_rehash : 1;
32 };
33 void strbuf_init(struct strbuf *, size_t);
34 void *hashmap_iter_next(struct hashmap_iter *iter);
35 void hashmap_free(struct hashmap *map, int free_entries);
36 void hashmap_iter_init(struct hashmap *map, struct hashmap_iter *iter);
37
38 void strbuf_release(struct strbuf *sb)
39 {
40 if (sb->alloc) { /* { dg-bogus "use after 'free'" } */
41 free(sb->buf);
42 strbuf_init(sb, 0);
43 }
44 }
45
46 void oid2strbuf_free(struct hashmap *map) {
47 struct hashmap_iter iter;
48 struct hashmap_entry *e;
49
50 hashmap_iter_init(map, &iter);
51 while ((e = hashmap_iter_next(&iter))) {
52 struct oid2strbuf *e_strbuf = (struct oid2strbuf *)e;
53 strbuf_release(e_strbuf->value); /* { dg-bogus "use after 'free'" } */
54 free(e_strbuf->value);
55 free(e);
56 }
57
58 hashmap_free(map, 0);
59 }
60