Fixes to Coverity tasks : 73267, 72686, 72672

Cleaned up warnings, and added checks to malloc return values and error log writes in case of failures.
This commit is contained in:
VilhoRaatikka
2014-10-31 15:25:59 +02:00
parent 848c7aa0b8
commit 00fded016b
9 changed files with 123 additions and 32 deletions

View File

@ -44,6 +44,10 @@
#include <skygw_debug.h>
#include <spinlock.h>
#include <hint.h>
#include <log_manager.h>
#include <errno.h>
extern int lm_enabled_logfiles_bitmask;
static buffer_object_t* gwbuf_remove_buffer_object(
GWBUF* buf,
@ -70,22 +74,23 @@ SHARED_BUF *sbuf;
/* Allocate the buffer header */
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
{
return NULL;
goto retblock;;
}
/* Allocate the shared data buffer */
if ((sbuf = (SHARED_BUF *)malloc(sizeof(SHARED_BUF))) == NULL)
{
free(rval);
return NULL;
goto retblock;
}
/* Allocate the space for the actual data */
if ((sbuf->data = (unsigned char *)malloc(size)) == NULL)
{
ss_dassert(sbuf->data != NULL);
free(rval);
free(sbuf);
return NULL;
goto retblock;
}
spinlock_init(&rval->gwbuf_lock);
rval->start = sbuf->data;
@ -100,6 +105,15 @@ SHARED_BUF *sbuf;
rval->gwbuf_info = GWBUF_INFO_NONE;
rval->gwbuf_bufobj = NULL;
CHK_GWBUF(rval);
retblock:
if (rval == NULL || sbuf == NULL || sbuf->data == NULL)
{
ss_dassert(rval != NULL && sbuf != NULL && sbuf->data != NULL);
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Memory allocation failed due to %s.",
strerror(errno))));
}
return rval;
}
@ -163,6 +177,11 @@ GWBUF *rval;
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
{
ss_dassert(rval != NULL);
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Memory allocation failed due to %s.",
strerror(errno))));
return NULL;
}
@ -194,6 +213,11 @@ GWBUF *gwbuf_clone_portion(
if ((clonebuf = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
{
ss_dassert(clonebuf != NULL);
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Memory allocation failed due to %s.",
strerror(errno))));
return NULL;
}
atomic_add(&buf->sbuf->refcount, 1);
@ -438,6 +462,16 @@ void gwbuf_add_buffer_object(
CHK_GWBUF(buf);
newb = (buffer_object_t *)malloc(sizeof(buffer_object_t));
ss_dassert(newb != NULL);
if (newb == NULL)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Memory allocation failed due to %s.",
strerror(errno))));
return;
}
newb->bo_id = id;
newb->bo_data = data;
newb->bo_donefun_fp = donefun_fp;
@ -518,8 +552,15 @@ gwbuf_add_property(GWBUF *buf, char *name, char *value)
BUF_PROPERTY *prop;
if ((prop = malloc(sizeof(BUF_PROPERTY))) == NULL)
{
ss_dassert(prop != NULL);
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Memory allocation failed due to %s.",
strerror(errno))));
return 0;
}
prop->name = strdup(name);
prop->value = strdup(value);
spinlock_acquire(&buf->gwbuf_lock);