[Libwebsockets] [libwebsockets] Crash when creating context with occupied port (#14)

"Andy Green (林安廸)" andy at warmcat.com
Tue Oct 22 00:52:25 CEST 2013


On 21/10/13 23:07, the mail apparently from fuzzy included:
> libwebsocket_create_context(...) crashes on a line 2163 of
> libwebsockets.c while trying to create a context for a port that is
> taken by the other instance of libwebsockets (i.e. an instance of
> websocket server with a port 9000 is running in a separate process and
> I'm trying to create a new websocket server on the very same port)
>
> if (n < 0) {
> lwsl_err("ERROR on binding to port %d (%d %d)\n",
> info->port, n, errno);
> close(sockfd); // this line leads to the crash
> goto bail;
> }
>
> commenting out the "close(sockfd);" line seems to solve the issue so
> libwebsocket_create_context is able to return NULL if a particular port
> is taken, but I don't think it's a proper way to solve this.

It's a Windows quirk unlike normal unixish OSes socket handles are not 
file handles, you have to close them with closesocket().  We have 
compatible_close() for this, I changed that and another example in the 
same function to use it, that should solve your problem without 
generating any new ones.

-Andy

>> Reply to this email directly or view it on GitHub
> <https://github.com/warmcat/libwebsockets/issues/14>.
>




More information about the Libwebsockets mailing list