Skip to content

Commit 999da23

Browse files
committed
itable: re-enable replace already existing value
This is a possible memory leak.
1 parent 1dadd80 commit 999da23

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

dttools/src/itable.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,9 @@ double itable_load(struct itable *h)
131131
static int insert_to_buckets_aux(struct entry **buckets, int bucket_count, struct entry *new_entry)
132132
{
133133
unsigned index;
134-
struct entry *e;
135-
136134
index = new_entry->key % bucket_count;
137-
e = buckets[index];
138-
139-
while (e) {
140-
/* check that this key does not already exist in the table */
141-
if (new_entry->key == e->key) {
142-
return 0;
143-
}
144-
e = e->next;
145-
}
146135

136+
// Possible memory leak! Silently replacing value if it existed.
147137
new_entry->next = buckets[index];
148138
buckets[index] = new_entry;
149139
return 1;

dttools/src/itable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ double itable_load(struct itable *h);
103103

104104

105105
/** Insert a key and value.
106-
This call will fail if the table already contains the same key.
107-
You must call @ref itable_remove to remove it.
106+
This call will replace the value if it already contains the same key.
108107
Also note that you cannot insert a null value into the table.
109108
@param h A pointer to an integer table.
110109
@param key An integer key

0 commit comments

Comments
 (0)