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