forked from xavi/libweb
Fix double-free on failed server_client_close
Even if server_client_close fails, it is needed for client_free to remove the dangling reference from h->clients.
This commit is contained in:
parent
65031ca350
commit
d438461f97
|
@ -152,13 +152,13 @@ static void client_free(struct client *const c)
|
|||
static int remove_client_from_list(struct handler *const h,
|
||||
struct client *const c)
|
||||
{
|
||||
int ret = -1;
|
||||
int ret = 0;
|
||||
|
||||
if (server_client_close(h->server, c->c))
|
||||
{
|
||||
fprintf(stderr, "%s: server_client_close failed\n",
|
||||
__func__);
|
||||
goto end;
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
for (struct client *cl = h->clients, *prev = NULL; cl;
|
||||
|
@ -175,9 +175,6 @@ static int remove_client_from_list(struct handler *const h,
|
|||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
end:
|
||||
client_free(c);
|
||||
return ret;
|
||||
}
|
||||
|
|
5
server.c
5
server.c
|
@ -54,12 +54,13 @@ int server_client_close(struct server *const s, struct server_client *const c)
|
|||
if (c == ref)
|
||||
{
|
||||
struct server_client *const next = ref->next;
|
||||
const int res = close(c->fd);
|
||||
|
||||
if ((ret = close(c->fd)))
|
||||
if (res)
|
||||
{
|
||||
fprintf(stderr, "%s: close(2): %s\n",
|
||||
__func__, strerror(errno));
|
||||
return -1;
|
||||
ret = -1;
|
||||
}
|
||||
else if (ref->prev)
|
||||
ref->prev->next = next;
|
||||
|
|
Loading…
Reference in New Issue