Skip to content

Commit

Permalink
ws-chat-server: fix session name initialization (using of uninitializ…
Browse files Browse the repository at this point in the history
…ed data)
  • Loading branch information
azat committed Nov 12, 2022
1 parent c8c730c commit 72a4fe7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sample/ws-chat-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,19 @@ on_ws(struct evhttp_request *req, void *arg)
socklen_t len;

client = calloc(sizeof(*client), 1);
addr2str((struct sockaddr *)&addr, client->name, sizeof(client->name));

client->evws = evws_new_session(req, on_msg_cb, client, 0);
if (!client->evws) {
free(client);
log_d("Failed to create session (for %s)\n", client->name);
log_d("Failed to create session\n");
return;
}

fd = bufferevent_getfd(evws_connection_get_bufferevent(client->evws));

len = sizeof(addr);
getpeername(fd, (struct sockaddr *)&addr, &len);
addr2str((struct sockaddr *)&addr, client->name, sizeof(client->name));

log_d("New client joined from %s\n", client->name);

Expand Down

0 comments on commit 72a4fe7

Please sign in to comment.