Fixes to Coverity defects.

This commit is contained in:
Markus Makela 2015-04-16 19:41:49 +03:00
parent cceca1b428
commit 1b3af7d61f
9 changed files with 32 additions and 35 deletions

View File

@ -2069,6 +2069,7 @@ config_get_ifaddr(unsigned char *output)
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) {
close(sock);
return 0;
}
@ -2085,6 +2086,7 @@ config_get_ifaddr(unsigned char *output)
}
}
} else {
close(sock);
return 0;
}
}

View File

@ -653,21 +653,27 @@ struct tm result;
char buf[30];
int i;
double idle = (hkheartbeat - ptr->client->last_read);
idle = idle > 0 ? idle/10.f:0;
dcb_printf(dcb, "Session %d (%p)\n",ptr->ses_id, ptr);
dcb_printf(dcb, "\tState: %s\n", session_state(ptr->state));
dcb_printf(dcb, "\tService: %s (%p)\n", ptr->service->name, ptr->service);
dcb_printf(dcb, "\tClient DCB: %p\n", ptr->client);
if (ptr->client && ptr->client->remote)
dcb_printf(dcb, "\tClient Address: %s%s%s\n",
ptr->client->user?ptr->client->user:"",
ptr->client->user?"@":"",
ptr->client->remote);
dcb_printf(dcb, "\tConnected: %s",
asctime_r(localtime_r(&ptr->stats.connect, &result), buf));
if(ptr->client->state == DCB_STATE_POLLING)
dcb_printf(dcb, "\tIdle: %.0f seconds",idle);
{
double idle = (hkheartbeat - ptr->client->last_read);
idle = idle > 0 ? idle/10.f:0;
dcb_printf(dcb, "\tClient Address: %s%s%s\n",
ptr->client->user?ptr->client->user:"",
ptr->client->user?"@":"",
ptr->client->remote);
dcb_printf(dcb, "\tConnected: %s",
asctime_r(localtime_r(&ptr->stats.connect, &result), buf));
if(ptr->client->state == DCB_STATE_POLLING)
{
dcb_printf(dcb, "\tIdle: %.0f seconds",idle);
}
}
if (ptr->n_filters)
{
for (i = 0; i < ptr->n_filters; i++)

View File

@ -973,12 +973,10 @@ bool parse_rule(char* rule, FW_INSTANCE* instance)
tok = strtok_r(NULL, " ,",&saveptr);
TIMERANGE *tr = NULL;
bool not_valid = false;
while(tok){
if(!check_time(tok))
{
not_valid = true;
skygw_log_write(LOGFILE_ERROR,"dbfwfilter: Rule parsing failed, malformed time definition: %s",tok);
rval = false;
goto retblock;
@ -1004,11 +1002,6 @@ bool parse_rule(char* rule, FW_INSTANCE* instance)
}
ruledef->active = tr;
if(not_valid)
{
continue;
}
}
else if(strcmp(tok,"regex") == 0)
{

View File

@ -1047,8 +1047,7 @@ clientReply (FILTER* instance, void *session, GWBUF *reply)
}
else
{
if(complete)
gwbuf_free(complete);
gwbuf_free(complete);
}
my_session->replies[branch]++;
@ -1264,7 +1263,7 @@ int internal_route(DCB* dcb)
GWBUF* clone_query(TEE_INSTANCE* my_instance, TEE_SESSION* my_session, GWBUF* buffer)
{
GWBUF* clone = NULL;
int length, residual;
int length, residual = 0;
char* ptr;
if (my_session->branch_session &&

View File

@ -1015,6 +1015,9 @@ int gw_MySQLListener(
int one = 1;
int rc;
memset(&serv_addr,0,sizeof(serv_addr));
memset(&local_addr,0,sizeof(local_addr));
if (strchr(config_bind, '/')) {
char *tmp = strrchr(config_bind, ':');
if (tmp)

View File

@ -1558,7 +1558,6 @@ int gw_find_mysql_user_password_sha1(char *username, uint8_t *gateway_password,
break;
}
break;
}
}

View File

@ -854,7 +854,7 @@ static void* newSession(
{
protocol->client_capabilities &= ~GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB;
strncpy(db,data->db,MYSQL_DATABASE_MAXLEN+1);
strncpy(db,data->db,MYSQL_DATABASE_MAXLEN);
memset(data->db,0,MYSQL_DATABASE_MAXLEN+1);
using_db = true;
skygw_log_write(LOGFILE_TRACE,"schemarouter: Client logging in directly to a database '%s', "

View File

@ -300,8 +300,8 @@ char* get_lenenc_str(void* data, int* len)
break;
case 0xfe:
size = *ptr + ((*(ptr + 2) << 8)) + (*(ptr + 3) << 16) +
(*(ptr + 4) << 24) + (*(ptr + 5) << 32) + (*(ptr + 6) << 40) +
(*(ptr + 7) << 48) + (*(ptr + 8) << 56);
(*(ptr + 4) << 24) + ((long)*(ptr + 5) << 32) + ((long)*(ptr + 6) << 40) +
((long)*(ptr + 7) << 48) + ((long)*(ptr + 8) << 56);
offset = 8;
break;
default:
@ -972,6 +972,7 @@ createInstance(SERVICE *service, char **options)
if((res_svc = calloc(sz, sizeof(SERVICE*))) == NULL)
{
free(router);
free(services);
skygw_log_write(LOGFILE_ERROR,"Error: Memory allocation failed.");
return NULL;
}
@ -1296,11 +1297,10 @@ freeSession(
void* router_client_session)
{
ROUTER_CLIENT_SES* router_cli_ses;
ROUTER_INSTANCE* router;
int i;
router_cli_ses = (ROUTER_CLIENT_SES *) router_client_session;
router = (ROUTER_INSTANCE *) router_instance;
/**
* For each property type, walk through the list, finalize properties
@ -2072,11 +2072,9 @@ subsvc_set_state(SUBSERVICE* svc,subsvc_state_t state)
{
if(state & SUBSVC_WAITING_RESULT)
{
int prev1;
/** Increase waiter count */
prev1 = atomic_add(&svc->n_res_waiting, 1);
ss_dassert(prev1 >= 0);
atomic_add(&svc->n_res_waiting, 1);
}
svc->state |= state;
@ -2089,11 +2087,8 @@ subsvc_clear_state(SUBSERVICE* svc,subsvc_state_t state)
if(state & SUBSVC_WAITING_RESULT)
{
int prev1;
/** Decrease waiter count */
prev1 = atomic_add(&svc->n_res_waiting, -1);
ss_dassert(prev1 >= 0);
atomic_add(&svc->n_res_waiting, -1);
}
svc->state &= ~state;

View File

@ -54,7 +54,7 @@ struct slist_st {
skygw_chk_t slist_chk_top;
slist_node_t* slist_head;
slist_node_t* slist_tail;
size_t slist_nelems;
int slist_nelems;
slist_t* slist_cursors_list;
skygw_chk_t slist_chk_tail;
};
@ -1046,7 +1046,7 @@ void slcursor_add_data(
}
/**
* Remove the current node in the slist. This does not delete the data in the
* Remove the node currently pointed by the cursor from the slist. This does not delete the data in the
* node but will delete the structure pointing to that data. This is useful when
* the user wants to free the allocated memory. After node removal, the cursor
* will point to the node before the removed node.