Fixes to Coverity issues 77197 (mysql_common.c, dcb.c, mysql_client.c, skygw_debug.h), 72654 (poll.c), 72756 (mysql_backend.c), 72744 (mysql_backend.c), 77197 (mysql_common.c), 72746 (mysql_common.c), 72676 (mysql_common.c), 72705 (readwritesplit.c), 72697 (readwritesplit.c), 72652 (skygw_debug.h)

This commit is contained in:
VilhoRaatikka
2014-11-11 14:10:06 +02:00
parent 704c69eb40
commit 061fa62d29
7 changed files with 138 additions and 114 deletions

View File

@ -509,10 +509,14 @@ bool succp = false;
pthread_self(),
dcb->fd,
dcb)));
#endif /* SS_DEBUG */
#if defined(FAKE_CODE)
conn_open[dcb->fd] = false;
#endif /* FAKE_CODE */
#if defined(SS_DEBUG)
ss_debug(dcb->fd = -1;)
}
#endif
#endif /* SS_DEBUG */
succp = dcb_set_state(dcb, DCB_STATE_DISCONNECTED, NULL);
ss_dassert(succp);
dcb_next = dcb->memdata.next;

View File

@ -1073,16 +1073,29 @@ double avg1 = 0.0, avg5 = 0.0, avg15 = 0.0;
{
char *event_string
= event_to_string(thread_data[i].event);
bool from_heap;
if (event_string == NULL)
{
from_heap = false;
event_string = "??";
}
else
{
from_heap = true;
}
dcb_printf(dcb,
" %2d | %-10s | %6d | %-16p | %s\n",
i, state, thread_data[i].n_fds,
thread_data[i].cur_dcb, event_string);
if (from_heap)
{
free(event_string);
}
}
}
}
/**
* The function used to calculate time based load data. This is called by the

View File

@ -270,6 +270,11 @@ static int gw_read_backend_event(DCB *dcb) {
CHK_SESSION(session);
if (session == NULL)
{
rc = 0;
goto return_with_lock;
}
router = session->service->router;
router_instance = session->service->router_instance;
rsession = session->router_session;
@ -1165,6 +1170,8 @@ static int backend_write_delayqueue(DCB *dcb)
CHK_SESSION(session);
if (session != NULL)
{
router = session->service->router;
router_instance = session->service->router_instance;
rsession = session->router_session;
@ -1189,18 +1196,15 @@ static int backend_write_delayqueue(DCB *dcb)
gwbuf_free(errbuf);
if (!succp)
{
if (session != NULL)
{
spinlock_acquire(&session->ses_lock);
session->state = SESSION_STATE_STOPPING;
spinlock_release(&session->ses_lock);
}
ss_dassert(dcb->dcb_errhandle_called);
dcb_close(dcb);
}
}
}
return rc;
}

View File

@ -1064,9 +1064,9 @@ int gw_MySQLListener(
strerror(errno));
return 0;
}
#if defined(SS_DEBUG)
#if defined(FAKE_CODE)
conn_open[l_so] = true;
#endif
#endif /* FAKE_CODE */
listen_dcb->func.accept = gw_MySQLAccept;
return 1;
@ -1197,8 +1197,10 @@ int gw_MySQLAccept(DCB *listener)
"%lu [gw_MySQLAccept] Accepted fd %d.",
pthread_self(),
c_sock)));
#endif /* SS_DEBUG */
#if defined(FAKE_CODE)
conn_open[c_sock] = true;
#endif
#endif /* FAKE_CODE */
/* set nonblocking */
sendbuf = GW_CLIENT_SO_SNDBUF;
setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &sendbuf, optlen);

View File

@ -750,8 +750,6 @@ int gw_do_connect_to_backend(
so = socket(AF_INET,SOCK_STREAM,0);
if (so < 0) {
int eno = errno;
errno = 0;
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error: Establishing connection to backend server "
@ -759,8 +757,8 @@ int gw_do_connect_to_backend(
"due %d, %s.",
host,
port,
eno,
strerror(eno))));
errno,
strerror(errno))));
rv = -1;
goto return_rv;
}
@ -771,8 +769,6 @@ int gw_do_connect_to_backend(
if(setsockopt(so, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize)) != 0)
{
int eno = errno;
errno = 0;
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error: Failed to set socket options "
@ -780,18 +776,16 @@ int gw_do_connect_to_backend(
"due %d, %s.",
host,
port,
eno,
strerror(eno))));
errno,
strerror(errno))));
rv = -1;
goto return_rv;
/** Close socket */
goto close_so;
}
bufsize = GW_BACKEND_SO_RCVBUF;
if(setsockopt(so, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize)) != 0)
{
int eno = errno;
errno = 0;
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error: Failed to set socket options "
@ -799,49 +793,35 @@ int gw_do_connect_to_backend(
"due %d, %s.",
host,
port,
eno,
strerror(eno))));
errno,
strerror(errno))));
rv = -1;
goto return_rv;
/** Close socket */
goto close_so;
}
/* set socket to as non-blocking here */
setnonblocking(so);
rv = connect(so, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
if (rv != 0) {
int eno = errno;
errno = 0;
if (eno == EINPROGRESS) {
if (rv != 0)
{
if (errno == EINPROGRESS)
{
rv = 1;
} else {
int rc;
int oldfd = so;
}
else
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error: Failed to connect backend server %s:%d, "
"due %d, %s.",
host,
port,
eno,
strerror(eno))));
/*< Close newly created socket. */
rc = close(so);
if (rc != 0) {
int eno = errno;
errno = 0;
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error: Failed to "
"close socket %d due %d, %s.",
oldfd,
eno,
strerror(eno))));
}
goto return_rv;
errno,
strerror(errno))));
/** Close socket */
goto close_so;
}
}
*fd = so;
@ -853,11 +833,26 @@ int gw_do_connect_to_backend(
host,
port,
so)));
#if defined(SS_DEBUG)
#if defined(FAKE_CODE)
conn_open[so] = true;
#endif
#endif /* FAKE_CODE */
return_rv:
return rv;
close_so:
/*< Close newly created socket. */
if (close(so) != 0)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error: Failed to "
"close socket %d due %d, %s.",
so,
errno,
strerror(errno))));
}
goto return_rv;
}
/**
@ -1770,11 +1765,14 @@ void protocol_archive_srv_command(
{
p->protocol_cmd_history = server_command_copy(s1);
}
else
else /*< scan and count history commands */
{
len += 1;
while (h1->scom_next != NULL)
{
h1 = h1->scom_next;
len += 1;
}
h1->scom_next = server_command_copy(s1);
}
@ -2067,7 +2065,7 @@ char* get_username_from_auth(
first_letter = (char *)(data + 4 + 4 + 4 + 1 + 23);
if (first_letter == '\0')
if (*first_letter == '\0')
{
rval = NULL;
goto retblock;

View File

@ -851,7 +851,9 @@ static void* newSession(
rses_end_locked_router_action(client_rses);
/** Both Master and at least 1 slave must be found */
/**
* Master and at least <min_nslaves> slaves must be found
*/
if (!succp) {
free(client_rses->rses_backend_ref);
free(client_rses);
@ -4101,15 +4103,17 @@ static void handleError (
}
session = backend_dcb->session;
if (session != NULL)
if (session == NULL || rses == NULL)
{
*succp = false;
return;
}
CHK_SESSION(session);
CHK_CLIENT_RSES(rses);
switch (action) {
case ERRACT_NEW_CONNECTION:
{
if (rses != NULL)
CHK_CLIENT_RSES(rses);
if (!rses_begin_locked_router_action(rses))
{
*succp = false;

View File

@ -183,8 +183,7 @@ typedef enum skygw_chk_t {
((p) == MYSQL_COM_QUIT ? "COM_QUIT" : \
((p) == MYSQL_COM_STMT_PREPARE ? "MYSQL_COM_STMT_PREPARE" : \
((p) == MYSQL_COM_STMT_EXECUTE ? "MYSQL_COM_STMT_EXECUTE" : \
((p) == MYSQL_COM_UNDEFINED ? "MYSQL_COM_UNDEFINED" : \
"UNKNOWN MYSQL PACKET TYPE")))))))))))))))))))
"UNKNOWN MYSQL PACKET TYPE"))))))))))))))))))
#define STRDCBSTATE(s) ((s) == DCB_STATE_ALLOC ? "DCB_STATE_ALLOC" : \
((s) == DCB_STATE_POLLING ? "DCB_STATE_POLLING" : \
@ -531,8 +530,8 @@ typedef enum skygw_chk_t {
#if defined(SS_DEBUG)
#if defined(FAKE_CODE)
bool conn_open[10240];
#endif
#endif /* FAKE_CODE */
#endif /* SKYGW_DEBUG_H */