From 9a82f91be11a5698c6f0da4dce665e081f3637d0 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 17 Mar 2017 19:50:18 +0100 Subject: Fix user_data structs not getting removed --- user_data.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/user_data.c b/user_data.c index 26e573a..5e7c028 100644 --- a/user_data.c +++ b/user_data.c @@ -25,6 +25,26 @@ static struct hash_item* find_userdata(i64 userid){ return item; } +static void remove_userdata(i64 userid){ + struct hash_item *item=user_hash[userid%USER_HASH_SIZE]; + assert(item); + if(item->data.userid==userid){ + user_hash[userid%USER_HASH_SIZE]=item->next; + free(item->data.fds); + free(item); + return; + } + struct hash_item *parent=NULL; + while(item->data.userid!=userid){ + parent=item; + item=item->next; + assert(item); + } + parent->next=item->next; + free(item->data.fds); + free(item); +} + void userdata_register(i64 userid,int fd){ struct hash_item *item=find_userdata(userid); if(item){ @@ -62,6 +82,9 @@ void userdata_unregister(i64 userid,int fd){ } memmove(item->data.fds+i,item->data.fds+i+1,item->data.fds_len-i-1); item->data.fds_len--; + if(item->data.fds_len==0){ + remove_userdata(userid); + } } const int* userdata_online(i64 userid,i64 *nfds){ -- cgit v1.2.3-70-g09d2