Properly initialize and destroy the mutex

This commit is contained in:
Jordan Bancino 2022-08-24 11:25:16 -04:00
parent 935f9db626
commit 8801afaeb2

View file

@ -119,6 +119,7 @@ HttpServerCreate(unsigned short port, unsigned int nThreads, unsigned int maxCon
free(server); free(server);
return NULL; return NULL;
} }
pthread_mutex_init(&server->connQueueMutex, NULL);
server->sd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); server->sd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
@ -165,6 +166,8 @@ HttpServerFree(HttpServer * server)
} }
close(server->sd); close(server->sd);
QueueFree(server->connQueue);
pthread_mutex_destroy(&server->connQueueMutex);
free(server); free(server);
} }
@ -186,7 +189,9 @@ HttpServerEventThread(void *args)
struct sockaddr_storage addr; struct sockaddr_storage addr;
socklen_t addrLen = sizeof(addr); socklen_t addrLen = sizeof(addr);
int connFd; int connFd;
int pollResult = poll(pollFds, 1, 500); int pollResult;
pollResult = poll(pollFds, 1, 500);
if (pollResult < 0) if (pollResult < 0)
{ {