aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-03-17 19:50:18 +0100
committertomsmeding <tom.smeding@gmail.com>2017-03-17 19:50:18 +0100
commit9a82f91be11a5698c6f0da4dce665e081f3637d0 (patch)
tree4ae8b4ac0d111d31aecab7fa12b8f25e3fad1e13
parentf63c5e78c33c5621b03594dd927b8a44651a584c (diff)
Fix user_data structs not getting removed
-rw-r--r--user_data.c23
1 files changed, 23 insertions, 0 deletions
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){