summaryrefslogtreecommitdiff
path: root/src/references.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2014-09-10 18:38:56 +0200
committerVicent Marti <tanoku@gmail.com>2014-09-10 18:38:56 +0200
commitc04e1e7aef06ce0836984b17e48a1d09bb83ce04 (patch)
tree505cfdf2734e703ce7212002d016565cb1ae0b76 /src/references.c
parent0a0a87333083058e945a54fcf196a6f119302d6b (diff)
Fix misc bugs
Diffstat (limited to 'src/references.c')
-rw-r--r--src/references.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/references.c b/src/references.c
index ff64b00..84cb773 100644
--- a/src/references.c
+++ b/src/references.c
@@ -13,6 +13,14 @@ refhash(const unsigned char *link_ref)
return hash;
}
+static void reference_free(reference *ref)
+{
+ free(ref->label);
+ free(ref->url);
+ free(ref->title);
+ free(ref);
+}
+
// normalize reference: collapse internal whitespace to single space,
// remove leading/trailing whitespace, case fold
static unsigned char *normalize_reference(chunk *ref)
@@ -28,7 +36,18 @@ static unsigned char *normalize_reference(chunk *ref)
static void add_reference(reference_map *map, reference* ref)
{
- ref->next = map->table[ref->hash % REFMAP_SIZE];
+ reference *t = ref->next = map->table[ref->hash % REFMAP_SIZE];
+
+ while (t) {
+ if (t->hash == ref->hash &&
+ !strcmp((char *)t->label, (char *)ref->label)) {
+ reference_free(ref);
+ return;
+ }
+
+ t = t->next;
+ }
+
map->table[ref->hash % REFMAP_SIZE] = ref;
}
@@ -63,7 +82,7 @@ reference* reference_lookup(reference_map *map, chunk *label)
ref = map->table[hash % REFMAP_SIZE];
while (ref) {
- if (ref->label[0] == norm[0] &&
+ if (ref->hash == hash &&
!strcmp((char *)ref->label, (char *)norm))
break;
ref = ref->next;
@@ -73,14 +92,6 @@ reference* reference_lookup(reference_map *map, chunk *label)
return ref;
}
-static void reference_free(reference *ref)
-{
- free(ref->label);
- free(ref->url);
- free(ref->title);
- free(ref);
-}
-
void reference_map_free(reference_map *map)
{
unsigned int i;
@@ -96,7 +107,6 @@ void reference_map_free(reference_map *map)
}
}
- free(map->table);
free(map);
}