Browse Source

api.c: Release apisock on error in api()

nfactor-troky
Maksym Borodin 11 years ago committed by Noel Maersk
parent
commit
d976abe12d
  1. 8
      api.c

8
api.c

@ -3682,6 +3682,7 @@ void api(int api_thr_id)
if (!opt_api_listen) { if (!opt_api_listen) {
applog(LOG_DEBUG, "API not running%s", UNAVAILABLE); applog(LOG_DEBUG, "API not running%s", UNAVAILABLE);
free(apisock);
return; return;
} }
@ -3699,6 +3700,7 @@ void api(int api_thr_id)
if (ips == 0) { if (ips == 0) {
applog(LOG_WARNING, "API not running (no valid IPs specified)%s", UNAVAILABLE); applog(LOG_WARNING, "API not running (no valid IPs specified)%s", UNAVAILABLE);
free(apisock);
return; return;
} }
} }
@ -3710,6 +3712,7 @@ void api(int api_thr_id)
*apisock = socket(AF_INET, SOCK_STREAM, 0); *apisock = socket(AF_INET, SOCK_STREAM, 0);
if (*apisock == INVSOCK) { if (*apisock == INVSOCK) {
applog(LOG_ERR, "API1 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE); applog(LOG_ERR, "API1 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE);
free(apisock);
return; return;
} }
@ -3721,6 +3724,7 @@ void api(int api_thr_id)
serv.sin_addr.s_addr = inet_addr(localaddr); serv.sin_addr.s_addr = inet_addr(localaddr);
if (serv.sin_addr.s_addr == (in_addr_t)INVINETADDR) { if (serv.sin_addr.s_addr == (in_addr_t)INVINETADDR) {
applog(LOG_ERR, "API2 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE); applog(LOG_ERR, "API2 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE);
free(apisock);
return; return;
} }
} }
@ -3759,12 +3763,14 @@ void api(int api_thr_id)
if (bound == 0) { if (bound == 0) {
applog(LOG_ERR, "API bind to port %d failed (%s)%s", port, binderror, UNAVAILABLE); applog(LOG_ERR, "API bind to port %d failed (%s)%s", port, binderror, UNAVAILABLE);
free(apisock);
return; return;
} }
if (SOCKETFAIL(listen(*apisock, QUEUE))) { if (SOCKETFAIL(listen(*apisock, QUEUE))) {
applog(LOG_ERR, "API3 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE); applog(LOG_ERR, "API3 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE);
CLOSESOCKET(*apisock); CLOSESOCKET(*apisock);
free(apisock);
return; return;
} }
@ -3901,6 +3907,8 @@ die:
; ;
pthread_cleanup_pop(true); pthread_cleanup_pop(true);
free(apisock);
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "API: terminating due to: %s", applog(LOG_DEBUG, "API: terminating due to: %s",
do_a_quit ? "QUIT" : (do_a_restart ? "RESTART" : (bye ? "BYE" : "UNKNOWN!"))); do_a_quit ? "QUIT" : (do_a_restart ? "RESTART" : (bye ? "BYE" : "UNKNOWN!")));

Loading…
Cancel
Save