]> jfr.im git - solanum.git/blobdiff - authd/provider.c
authd: fix memory leak in start_auth
[solanum.git] / authd / provider.c
index 78bade6abafeb2e19c329dbf12ef11260979029c..119918776af2d43ad0871e738484c2fada2b79f5 100644 (file)
@@ -182,6 +182,11 @@ auth_client_free(struct auth_client *auth)
 void
 cancel_providers(struct auth_client *auth)
 {
+       if(auth->providers_cancelled)
+               return;
+
+       auth->providers_cancelled = true;
+
        if(auth->refcount > 0)
        {
                rb_dlink_node *ptr;
@@ -274,13 +279,14 @@ accept_client(struct auth_client *auth, uint32_t id)
 static void
 start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ip, const char *c_port)
 {
-       struct auth_client *auth = rb_malloc(sizeof(struct auth_client));
+       struct auth_client *auth;
        long lcid = strtol(cid, NULL, 16);
        rb_dlink_node *ptr;
 
        if(lcid >= UINT32_MAX)
                return;
 
+       auth = rb_malloc(sizeof(struct auth_client));
        auth->cid = (uint32_t)lcid;
 
        if(rb_dictionary_find(auth_clients, RB_UINT_TO_POINTER(auth->cid)) == NULL)
@@ -323,6 +329,9 @@ start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_
                if(!provider->start(auth))
                        /* Rejected immediately */
                        return;
+
+               if(auth->providers_cancelled)
+                       break;
        }
        auth->providers_starting = false;