|  | @@ -9387,8 +9387,7 @@ mg_websocket_write_exec(struct mg_connection *conn,
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	int retval = -1;
 |  |  	int retval = -1;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -	header[0] = (unsigned char)0x80u
 |  | 
 | 
											
												
													
														|  | -	            + (((unsigned char)(unsigned)opcode) & (unsigned char)0xFu);
 |  | 
 | 
											
												
													
														|  | 
 |  | +	header[0] = 0x80u | (opcode & 0xf);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	/* Frame format: http://tools.ietf.org/html/rfc6455#section-5.2 */
 |  |  	/* Frame format: http://tools.ietf.org/html/rfc6455#section-5.2 */
 | 
											
												
													
														|  |  	if (dataLen < 126) {
 |  |  	if (dataLen < 126) {
 | 
											
										
											
												
													
														|  | @@ -13617,6 +13616,10 @@ free_context(struct mg_context *ctx)
 | 
											
												
													
														|  |  #endif
 |  |  #endif
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  		pthread_key_delete(sTlsKey);
 |  |  		pthread_key_delete(sTlsKey);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +#if defined(USE_LUA)
 | 
											
												
													
														|  | 
 |  | +		lua_exit_optional_libraries();
 | 
											
												
													
														|  | 
 |  | +#endif
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	/* deallocate system name string */
 |  |  	/* deallocate system name string */
 | 
											
										
											
												
													
														|  | @@ -13754,6 +13757,11 @@ mg_start(const struct mg_callbacks *callbacks,
 | 
											
												
													
														|  |  			mg_free(ctx);
 |  |  			mg_free(ctx);
 | 
											
												
													
														|  |  			return NULL;
 |  |  			return NULL;
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +#if defined(USE_LUA)
 | 
											
												
													
														|  | 
 |  | +		lua_init_optional_libraries();
 | 
											
												
													
														|  | 
 |  | +#endif
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  	} else {
 |  |  	} else {
 | 
											
												
													
														|  |  		/* TODO (low): istead of sleeping, check if sTlsKey is already
 |  |  		/* TODO (low): istead of sleeping, check if sTlsKey is already
 | 
											
												
													
														|  |  		 * initialized. */
 |  |  		 * initialized. */
 | 
											
										
											
												
													
														|  | @@ -13767,10 +13775,6 @@ mg_start(const struct mg_callbacks *callbacks,
 | 
											
												
													
														|  |  #endif
 |  |  #endif
 | 
											
												
													
														|  |  	pthread_setspecific(sTlsKey, &tls);
 |  |  	pthread_setspecific(sTlsKey, &tls);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -#if defined(USE_LUA)
 |  | 
 | 
											
												
													
														|  | -	lua_init_optional_libraries();
 |  | 
 | 
											
												
													
														|  | -#endif
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |  	ok = 0 == pthread_mutex_init(&ctx->thread_mutex, &pthread_mutex_attr);
 |  |  	ok = 0 == pthread_mutex_init(&ctx->thread_mutex, &pthread_mutex_attr);
 | 
											
												
													
														|  |  #if !defined(ALTERNATIVE_QUEUE)
 |  |  #if !defined(ALTERNATIVE_QUEUE)
 | 
											
												
													
														|  |  	ok &= 0 == pthread_cond_init(&ctx->sq_empty, NULL);
 |  |  	ok &= 0 == pthread_cond_init(&ctx->sq_empty, NULL);
 |