From 45022746b7f05aab62ffb87cc1656f4c8bef31e4 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 3 Apr 2001 16:40:57 +0000 Subject: [PATCH] updates. --- lib/silccore/idcache.c | 12 +++++++++--- lib/silccore/silcsockconn.c | 30 ++++++++++++++++++------------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/lib/silccore/idcache.c b/lib/silccore/idcache.c index 5d8d793c..c7c61857 100644 --- a/lib/silccore/idcache.c +++ b/lib/silccore/idcache.c @@ -204,8 +204,10 @@ int silc_idcache_find_by_data(SilcIDCache cache, unsigned char *data, silc_idcache_list_add(list, &(cache->cache[i])); } - if (!silc_idcache_list_count(list)) + if (!silc_idcache_list_count(list)) { + silc_idcache_list_free(list); return FALSE; + } if (ret) *ret = list; @@ -295,8 +297,10 @@ int silc_idcache_find_by_data_loose(SilcIDCache cache, unsigned char *data, } } - if (!silc_idcache_list_count(list)) + if (!silc_idcache_list_count(list)) { + silc_idcache_list_free(list); return FALSE; + } if (ret) *ret = list; @@ -332,8 +336,10 @@ int silc_idcache_find_by_id(SilcIDCache cache, void *id, SilcIdType type, silc_idcache_list_add(list, &(cache->cache[i])); } - if (!silc_idcache_list_count(list)) + if (!silc_idcache_list_count(list)) { + silc_idcache_list_free(list); return FALSE; + } if (ret) *ret = list; diff --git a/lib/silccore/silcsockconn.c b/lib/silccore/silcsockconn.c index 3b5af118..4de42da0 100644 --- a/lib/silccore/silcsockconn.c +++ b/lib/silccore/silcsockconn.c @@ -106,16 +106,22 @@ void silc_socket_set_heartbeat(SilcSocketConnection sock, SilcSocketConnectionHBCb hb_callback, void *timeout_queue) { - SilcSocketConnectionHB hb = silc_calloc(1, sizeof(*hb)); - - hb->heartbeat = heartbeat; - hb->hb_context = hb_context; - hb->hb_callback = hb_callback; - hb->timeout_queue = timeout_queue; - hb->sock = sock; - hb->hb_task = silc_task_register(timeout_queue, sock->sock, - silc_socket_heartbeat, - (void *)hb, heartbeat, 0, - SILC_TASK_TIMEOUT, - SILC_TASK_PRI_LOW); + + if (sock->hb) { + silc_task_unregister(sock->hb->timeout_queue, sock->hb->hb_task); + silc_free(sock->hb->hb_context); + silc_free(sock->hb); + } + + sock->hb = silc_calloc(1, sizeof(*sock->hb)); + sock->hb->heartbeat = heartbeat; + sock->hb->hb_context = hb_context; + sock->hb->hb_callback = hb_callback; + sock->hb->timeout_queue = timeout_queue; + sock->hb->sock = sock; + sock->hb->hb_task = silc_task_register(timeout_queue, sock->sock, + silc_socket_heartbeat, + (void *)sock->hb, heartbeat, 0, + SILC_TASK_TIMEOUT, + SILC_TASK_PRI_LOW); } -- 2.43.0