Fixes to Coverity issues 72703, 72713, 72718, 72721
This commit is contained in:
@ -30,6 +30,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <filter.h>
|
#include <filter.h>
|
||||||
#include <session.h>
|
#include <session.h>
|
||||||
#include <modules.h>
|
#include <modules.h>
|
||||||
@ -328,27 +329,43 @@ DOWNSTREAM *me;
|
|||||||
if ((filter->obj = load_module(filter->module,
|
if ((filter->obj = load_module(filter->module,
|
||||||
MODULE_FILTER)) == NULL)
|
MODULE_FILTER)) == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
me = NULL;
|
||||||
|
goto retblock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter->filter == NULL)
|
if (filter->filter == NULL)
|
||||||
{
|
{
|
||||||
if ((filter->filter = (filter->obj->createInstance)(filter->options,
|
if ((filter->filter = (filter->obj->createInstance)(filter->options,
|
||||||
filter->parameters)) == NULL)
|
filter->parameters)) == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
me = NULL;
|
||||||
|
goto retblock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((me = (DOWNSTREAM *)calloc(1, sizeof(DOWNSTREAM))) == NULL)
|
if ((me = (DOWNSTREAM *)calloc(1, sizeof(DOWNSTREAM))) == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Memory allocation for filter session failed "
|
||||||
|
"due to %d,%s.",
|
||||||
|
errno,
|
||||||
|
strerror(errno))));
|
||||||
|
|
||||||
|
goto retblock;
|
||||||
}
|
}
|
||||||
me->instance = filter->filter;
|
me->instance = filter->filter;
|
||||||
me->routeQuery = (void *)(filter->obj->routeQuery);
|
me->routeQuery = (void *)(filter->obj->routeQuery);
|
||||||
me->session = filter->obj->newSession(me->instance, session);
|
|
||||||
|
|
||||||
|
if ((me->session=filter->obj->newSession(me->instance, session)) == NULL)
|
||||||
|
{
|
||||||
|
free(me);
|
||||||
|
me = NULL;
|
||||||
|
goto retblock;
|
||||||
|
}
|
||||||
filter->obj->setDownstream(me->instance, me->session, downstream);
|
filter->obj->setDownstream(me->instance, me->session, downstream);
|
||||||
|
|
||||||
|
retblock:
|
||||||
return me;
|
return me;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -668,7 +668,8 @@ int i;
|
|||||||
{
|
{
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
LOGFILE_ERROR,
|
LOGFILE_ERROR,
|
||||||
"Failed to create filter '%s' for service '%s'.\n",
|
"Error : Failed to create filter '%s' for "
|
||||||
|
"service '%s'.\n",
|
||||||
service->filters[i]->name,
|
service->filters[i]->name,
|
||||||
service->name)));
|
service->name)));
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -673,7 +673,7 @@ int get_timestamp_len(void)
|
|||||||
* Write position in memory. Must be filled with at least
|
* Write position in memory. Must be filled with at least
|
||||||
* <timestamp_len> zeroes
|
* <timestamp_len> zeroes
|
||||||
*
|
*
|
||||||
* @return Length of string written. Length includes terminating '\0'.
|
* @return Length of string written to p_ts. Length includes terminating '\0'.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @details (write detailed description here)
|
* @details (write detailed description here)
|
||||||
@ -685,9 +685,11 @@ int snprint_timestamp(
|
|||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
int rval;
|
||||||
|
|
||||||
if (p_ts == NULL) {
|
if (p_ts == NULL) {
|
||||||
goto return_p_ts;
|
rval = 0;
|
||||||
|
goto retblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Generate timestamp */
|
/** Generate timestamp */
|
||||||
@ -703,8 +705,9 @@ int snprint_timestamp(
|
|||||||
tm.tm_min,
|
tm.tm_min,
|
||||||
tm.tm_sec);
|
tm.tm_sec);
|
||||||
|
|
||||||
return_p_ts:
|
rval = strlen(p_ts);
|
||||||
return (strlen(p_ts));
|
retblock:
|
||||||
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -964,13 +967,11 @@ void slcursor_add_data(
|
|||||||
CHK_SLIST_CURSOR(c);
|
CHK_SLIST_CURSOR(c);
|
||||||
list = c->slcursor_list;
|
list = c->slcursor_list;
|
||||||
CHK_SLIST(list);
|
CHK_SLIST(list);
|
||||||
pos = c->slcursor_pos;
|
if (c->slcursor_pos != NULL)
|
||||||
|
{
|
||||||
if (pos != NULL) {
|
CHK_SLIST_NODE(c->slcursor_pos);
|
||||||
CHK_SLIST_NODE(pos);
|
|
||||||
pos = list->slist_tail->slnode_next;
|
|
||||||
}
|
}
|
||||||
ss_dassert(pos == NULL);
|
ss_dassert(list->slist_tail->slnode_next == NULL);
|
||||||
pos = slist_node_init(data, c);
|
pos = slist_node_init(data, c);
|
||||||
slist_add_node(list, pos);
|
slist_add_node(list, pos);
|
||||||
CHK_SLIST(list);
|
CHK_SLIST(list);
|
||||||
@ -1291,7 +1292,7 @@ simple_mutex_t* simple_mutex_init(
|
|||||||
|
|
||||||
/** Write zeroes if flat, free otherwise. */
|
/** Write zeroes if flat, free otherwise. */
|
||||||
if (sm->sm_flat) {
|
if (sm->sm_flat) {
|
||||||
memset(sm, 0, sizeof(sm));
|
memset(sm, 0, sizeof(*sm));
|
||||||
} else {
|
} else {
|
||||||
simple_mutex_free_memory(sm);
|
simple_mutex_free_memory(sm);
|
||||||
sm = NULL;
|
sm = NULL;
|
||||||
@ -1761,7 +1762,7 @@ bool skygw_file_write(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
CHK_FILE(file);
|
CHK_FILE(file);
|
||||||
#if (LAPTOP_TEST)
|
#if defined(LAPTOP_TEST)
|
||||||
usleep(DISKWRITE_LATENCY);
|
usleep(DISKWRITE_LATENCY);
|
||||||
#else
|
#else
|
||||||
nwritten = fwrite(data, nbytes, 1, file->sf_file);
|
nwritten = fwrite(data, nbytes, 1, file->sf_file);
|
||||||
@ -1777,7 +1778,8 @@ bool skygw_file_write(
|
|||||||
}
|
}
|
||||||
writecount += 1;
|
writecount += 1;
|
||||||
|
|
||||||
if (flush || writecount == FSYNCLIMIT) {
|
if (flush || writecount == FSYNCLIMIT)
|
||||||
|
{
|
||||||
fd = fileno(file->sf_file);
|
fd = fileno(file->sf_file);
|
||||||
err = fflush(file->sf_file);
|
err = fflush(file->sf_file);
|
||||||
err = fsync(fd);
|
err = fsync(fd);
|
||||||
@ -1796,21 +1798,21 @@ skygw_file_t* skygw_file_init(
|
|||||||
{
|
{
|
||||||
skygw_file_t* file;
|
skygw_file_t* file;
|
||||||
|
|
||||||
file = (skygw_file_t *)calloc(1, sizeof(skygw_file_t));
|
if ((file = (skygw_file_t *)calloc(1, sizeof(skygw_file_t))) == NULL)
|
||||||
|
{
|
||||||
if (file == NULL) {
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"* Memory allocation for skygw file failed.\n");
|
"* Error : Memory allocation for file %s failed.\n",
|
||||||
|
fname);
|
||||||
perror("SkyGW file allocation\n");
|
perror("SkyGW file allocation\n");
|
||||||
|
goto return_file;
|
||||||
}
|
}
|
||||||
ss_dassert(file != NULL);
|
ss_dassert(file != NULL);
|
||||||
file->sf_chk_top = CHK_NUM_FILE;
|
file->sf_chk_top = CHK_NUM_FILE;
|
||||||
file->sf_chk_tail = CHK_NUM_FILE;
|
file->sf_chk_tail = CHK_NUM_FILE;
|
||||||
file->sf_fname = strdup(fname);
|
file->sf_fname = strdup(fname);
|
||||||
|
|
||||||
file->sf_file = fopen(file->sf_fname, "a");
|
if ((file->sf_file = fopen(file->sf_fname, "a")) == NULL)
|
||||||
|
{
|
||||||
if (file->sf_file == NULL) {
|
|
||||||
int eno = errno;
|
int eno = errno;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@ -1824,7 +1826,8 @@ skygw_file_t* skygw_file_init(
|
|||||||
}
|
}
|
||||||
setvbuf(file->sf_file, NULL, _IONBF, 0);
|
setvbuf(file->sf_file, NULL, _IONBF, 0);
|
||||||
|
|
||||||
if (!file_write_header(file)) {
|
if (!file_write_header(file))
|
||||||
|
{
|
||||||
int eno = errno;
|
int eno = errno;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
|||||||
Reference in New Issue
Block a user