@@ -284,9 +284,12 @@ ESL_DECLARE(int) esl_snprintf(char *buffer, size_t count, const char *fmt, ...)
284284
285285static void null_logger (const char * file , const char * func , int line , int level , const char * fmt , ...)
286286{
287- if (file && func && line && level && fmt ) {
288- return ;
289- }
287+ (void )file ;
288+ (void )func ;
289+ (void )line ;
290+ (void )level ;
291+ (void )fmt ;
292+
290293 return ;
291294}
292295
@@ -696,7 +699,10 @@ ESL_DECLARE(esl_status_t) esl_listen(const char *host, esl_port_t port, esl_list
696699 }
697700
698701
699- esl_socket_reuseaddr (server_sock );
702+ if (esl_socket_reuseaddr (server_sock ) != 0 ) {
703+ status = ESL_FAIL ;
704+ goto end ;
705+ }
700706
701707 memset (& addr , 0 , sizeof (addr ));
702708 addr .sin_family = AF_INET ;
@@ -751,7 +757,10 @@ ESL_DECLARE(esl_status_t) esl_listen_threaded(const char *host, esl_port_t port,
751757 return ESL_FAIL ;
752758 }
753759
754- esl_socket_reuseaddr (server_sock );
760+ if (esl_socket_reuseaddr (server_sock ) != 0 ) {
761+ status = ESL_FAIL ;
762+ goto end ;
763+ }
755764
756765 memset (& addr , 0 , sizeof (addr ));
757766 addr .sin_family = AF_INET ;
@@ -1060,7 +1069,10 @@ ESL_DECLARE(esl_status_t) esl_connect_timeout(esl_handle_t *handle, const char *
10601069 }
10611070 }
10621071#else
1063- fcntl (handle -> sock , F_SETFL , fd_flags );
1072+ if (fcntl (handle -> sock , F_SETFL , fd_flags )) {
1073+ snprintf (handle -> err , sizeof (handle -> err ), "Socket Connection Error" );
1074+ goto fail ;
1075+ }
10641076#endif
10651077 rval = 0 ;
10661078 }
@@ -1155,20 +1167,20 @@ ESL_DECLARE(esl_status_t) esl_disconnect(esl_handle_t *handle)
11551167 esl_event_safe_destroy (& handle -> last_ievent );
11561168 esl_event_safe_destroy (& handle -> info_event );
11571169
1158- if (mutex ) {
1159- esl_mutex_unlock (mutex );
1160- esl_mutex_lock (mutex );
1161- esl_mutex_unlock (mutex );
1162- esl_mutex_destroy (& mutex );
1163- }
1164-
11651170 if (handle -> packet_buf ) {
11661171 esl_buffer_destroy (& handle -> packet_buf );
11671172 }
11681173
11691174 memset (handle , 0 , sizeof (* handle ));
11701175 handle -> destroyed = 1 ;
11711176
1177+ if (mutex ) {
1178+ esl_mutex_unlock (mutex );
1179+ esl_mutex_lock (mutex );
1180+ esl_mutex_unlock (mutex );
1181+ esl_mutex_destroy (& mutex );
1182+ }
1183+
11721184 return status ;
11731185}
11741186
@@ -1217,7 +1229,7 @@ ESL_DECLARE(esl_status_t) esl_recv_event_timed(esl_handle_t *handle, uint32_t ms
12171229 status = ESL_BREAK ;
12181230 }
12191231
1220- if ( handle -> mutex ) esl_mutex_unlock (handle -> mutex );
1232+ esl_mutex_unlock (handle -> mutex );
12211233
12221234 return status ;
12231235
@@ -1299,14 +1311,12 @@ ESL_DECLARE(esl_status_t) esl_recv_event(esl_handle_t *handle, int check_q, esl_
12991311 * e ++ = '\0' ;
13001312 while (* e == '\n' || * e == '\r' ) e ++ ;
13011313
1302- if (hval ) {
1303- esl_url_decode (hval );
1304- esl_log (ESL_LOG_DEBUG , "RECV HEADER [%s] = [%s]\n" , hname , hval );
1305- if (!strncmp (hval , "ARRAY::" , 7 )) {
1306- esl_event_add_array (revent , hname , hval );
1307- } else {
1308- esl_event_add_header_string (revent , ESL_STACK_BOTTOM , hname , hval );
1309- }
1314+ esl_url_decode (hval );
1315+ esl_log (ESL_LOG_DEBUG , "RECV HEADER [%s] = [%s]\n" , hname , hval );
1316+ if (!strncmp (hval , "ARRAY::" , 7 )) {
1317+ esl_event_add_array (revent , hname , hval );
1318+ } else {
1319+ esl_event_add_header_string (revent , ESL_STACK_BOTTOM , hname , hval );
13101320 }
13111321
13121322 p = e ;
@@ -1521,11 +1531,15 @@ ESL_DECLARE(esl_status_t) esl_send_recv_timed(esl_handle_t *handle, const char *
15211531 const char * hval ;
15221532 esl_status_t status ;
15231533
1524- if (!handle || ! handle -> connected || handle -> sock == ESL_SOCK_INVALID ) {
1525- return ESL_FAIL ;
1526- }
1534+ if (!handle ) {
1535+ return ESL_FAIL ;
1536+ }
15271537
15281538 esl_mutex_lock (handle -> mutex );
1539+ if (!handle -> connected || handle -> sock == ESL_SOCK_INVALID ) {
1540+ esl_mutex_unlock (handle -> mutex );
1541+ return ESL_FAIL ;
1542+ }
15291543
15301544 esl_event_safe_destroy (& handle -> last_sr_event );
15311545
0 commit comments