Fix refcnting bug in DTLS
I think this is right. It's odd to up the refcnt on every set_dtls. We're
just setting the value. IIUC, the refcnt is meant to keep key alive since
we're storing a ref to it in V.
This bug was probably harmless - just some wasted memory. You'd need 4
billion set_dtls calls followed by a poorly timed decref to cause serious
trouble. =)
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/user/parlib/dtls.c b/user/parlib/dtls.c
index afd8e28..4df4d54 100644
--- a/user/parlib/dtls.c
+++ b/user/parlib/dtls.c
@@ -170,11 +170,11 @@
static inline void __set_dtls(dtls_data_t *dtls_data, dtls_key_t key, void *dtls)
{
assert(key);
- __sync_fetch_and_add(&key->ref_count, 1);
struct dtls_value *v = __get_dtls(dtls_data, key);
if (!v) {
v = __allocate_dtls_value(dtls_data, key);
+ __sync_fetch_and_add(&key->ref_count, 1);
v->key = key;
TAILQ_INSERT_HEAD(&dtls_data->list, v, link);
}