if (origin) {
wsi->c_origin = (char *)malloc(strlen(origin) + 1);
- strcpy(wsi->c_origin, origin);
if (wsi->c_origin == NULL)
goto oom2;
+ strcpy(wsi->c_origin, origin);
} else
wsi->c_origin = NULL;
ext->per_context_private_data = malloc(
sizeof (struct lws_ext_x_google_mux_context));
+ if (ext->per_context_private_data == NULL) {
+ lwsl_err("Out of memory\n");
+ return -1;
+ }
mux_ctx = (struct lws_ext_x_google_mux_context *)
ext->per_context_private_data;
mux_ctx->active_conns = 0;
wsi->active_extensions_user[
wsi->count_active_extensions] =
malloc(ext->per_session_data_size);
+ if (wsi->active_extensions_user[
+ wsi->count_active_extensions] == NULL) {
+ lwsl_err("Out of mem\n");
+ free(response);
+ goto bail;
+ }
memset(wsi->active_extensions_user[
wsi->count_active_extensions], 0,
ext->per_session_data_size);
wsi->active_extensions_user[
wsi->count_active_extensions] =
malloc(ext->per_session_data_size);
+ if (wsi->active_extensions_user[
+ wsi->count_active_extensions] == NULL) {
+ lwsl_err("Out of mem\n");
+ goto bail2;
+ }
memset(wsi->active_extensions_user[
wsi->count_active_extensions], 0,
ext->per_session_data_size);
if (context->fds_count >= MAX_CLIENTS) {
lwsl_err("too busy to accept new broadcast "
"proxy client\n");
-#ifdef WIN32
- closesocket(accept_fd);
-#else
- close(accept_fd);
-#endif
- break;
+ goto bail_prox_listener;
}
/* create a dummy wsi for the connection and add it */
new_wsi = (struct libwebsocket *)malloc(sizeof(struct libwebsocket));
+ if (new_wsi == NULL) {
+ lwsl_err("Out of mem\n");
+ goto bail_prox_listener;
+ }
memset(new_wsi, 0, sizeof (struct libwebsocket));
new_wsi->sock = accept_fd;
new_wsi->mode = LWS_CONNMODE_BROADCAST_PROXY;
break;
+bail_prox_listener:
+#ifdef WIN32
+ closesocket(accept_fd);
+#else
+ close(accept_fd);
+#endif
+ break;
+
case LWS_CONNMODE_BROADCAST_PROXY:
/* handle session socket closed */
if (n < 0) {
lwsl_err("ERROR on binding to port %d (%d %d)\n",
port, n, errno);
+ close(sockfd);
return NULL;
}
wsi = (struct libwebsocket *)malloc(sizeof(struct libwebsocket));
+ if (wsi == NULL) {
+ lwsl_err("Out of mem\n");
+ close(sockfd);
+ return NULL;
+ }
memset(wsi, 0, sizeof (struct libwebsocket));
wsi->sock = sockfd;
wsi->count_active_extensions = 0;
/* dummy wsi per broadcast proxy socket */
wsi = (struct libwebsocket *)malloc(sizeof(struct libwebsocket));
+ if (wsi == NULL) {
+ lwsl_err("Out of mem\n");
+ close(fd);
+ return NULL;
+ }
memset(wsi, 0, sizeof (struct libwebsocket));
wsi->sock = fd;
wsi->mode = LWS_CONNMODE_BROADCAST_PROXY_LISTENER;
wsi->utf8_token[wsi->parser_state].token = (char *)
realloc(wsi->utf8_token[wsi->parser_state].token,
wsi->current_alloc_len);
+ if (wsi->utf8_token[wsi->parser_state].token == NULL) {
+ lwsl_err("Out of mem\n");
+ return -1;
+ }
}
/* bail at EOL */
wsi->utf8_token[wsi->parser_state].token = (char *)
malloc(wsi->current_alloc_len);
+ if (wsi->utf8_token[wsi->parser_state].token == NULL) {
+ lwsl_err("Out of mem\n");
+ return -1;
+ }
wsi->utf8_token[wsi->parser_state].token_len = 0;
break;
wsi->current_alloc_len = LWS_INITIAL_HDR_ALLOC;
wsi->utf8_token[wsi->parser_state].token = (char *)
malloc(wsi->current_alloc_len);
+ if (wsi->utf8_token[wsi->parser_state].token == NULL) {
+ lwsl_err("Out of mem\n");
+ return -1;
+ }
wsi->utf8_token[wsi->parser_state].token_len = 0;
}
wsi->current_alloc_len = LWS_INITIAL_HDR_ALLOC;
wsi->utf8_token[WSI_TOKEN_GET_URI].token =
(char *)malloc(wsi->current_alloc_len);
+ if (wsi->utf8_token[WSI_TOKEN_GET_URI].token == NULL) {
+ lwsl_err("Out of mem\n");
+ return -1;
+ }
break;
}
}