Skip to content

Commit

Permalink
Add hash_remove and use in transp to fix creytiv#261
Browse files Browse the repository at this point in the history
  • Loading branch information
balgillo committed Sep 6, 2022
1 parent cae2bcb commit 58e7504
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/re_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct pl;
int hash_alloc(struct hash **hp, uint32_t bsize);
void hash_append(struct hash *h, uint32_t key, struct le *le, void *data);
void hash_unlink(struct le *le);
void hash_remove(struct le *le);
struct le *hash_lookup(const struct hash *h, uint32_t key, list_apply_h *ah,
void *arg);
struct le *hash_apply(const struct hash *h, list_apply_h *ah, void *arg);
Expand Down
17 changes: 17 additions & 0 deletions src/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ void hash_unlink(struct le *le)
}


/**
* If the element is present in the hashmap table, unlink it and deref the object,
* otherwise do nothing. This is like hash_flush but for a single entry.
*
* @param le List element
*/
void hash_remove(struct le *le)
{
if (le->list != NULL)
{
void *data = le->data;
list_unlink(le);
mem_deref(data);
}
}


/**
* Apply a handler function to all elements in the hashmap with a matching key
*
Expand Down
6 changes: 1 addition & 5 deletions src/sip/transp.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ static void conn_close(struct sip_conn *conn, int err)
conn->tc = mem_deref(conn->tc);
tmr_cancel(&conn->tmr_ka);
tmr_cancel(&conn->tmr);
hash_unlink(&conn->he);

le = list_head(&conn->ql);

Expand All @@ -195,6 +194,7 @@ static void conn_close(struct sip_conn *conn, int err)
}

sip_keepalive_signal(&conn->kal, err);
hash_remove(&conn->he);
}


Expand All @@ -203,7 +203,6 @@ static void conn_tmr_handler(void *arg)
struct sip_conn *conn = arg;

conn_close(conn, ETIMEDOUT);
mem_deref(conn);
}


Expand All @@ -221,7 +220,6 @@ static void conn_keepalive_handler(void *arg)
err = tcp_send(conn->tc, &mb);
if (err) {
conn_close(conn, err);
mem_deref(conn);
return;
}

Expand Down Expand Up @@ -448,7 +446,6 @@ static void tcp_recv_handler(struct mbuf *mb, void *arg)
out:
if (err) {
conn_close(conn, err);
mem_deref(conn);
}
}

Expand Down Expand Up @@ -492,7 +489,6 @@ static void tcp_close_handler(int err, void *arg)
struct sip_conn *conn = arg;

conn_close(conn, err ? err : ECONNRESET);
mem_deref(conn);
}


Expand Down

0 comments on commit 58e7504

Please sign in to comment.