Coverity : 72678, 72687, 72689

Fixed memory leaks and use of freed memory
This commit is contained in:
VilhoRaatikka
2014-10-30 18:19:41 +02:00
parent 9d466b5770
commit 7048270062
2 changed files with 52 additions and 11 deletions

View File

@ -338,6 +338,12 @@ static bool logmanager_init_nomutex(
bool succp = false; bool succp = false;
lm = (logmanager_t *)calloc(1, sizeof(logmanager_t)); lm = (logmanager_t *)calloc(1, sizeof(logmanager_t));
if (lm == NULL)
{
err = 1;
goto return_succp;
}
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
lm->lm_chk_top = CHK_NUM_LOGMANAGER; lm->lm_chk_top = CHK_NUM_LOGMANAGER;
lm->lm_chk_tail = CHK_NUM_LOGMANAGER; lm->lm_chk_tail = CHK_NUM_LOGMANAGER;
@ -347,7 +353,15 @@ static bool logmanager_init_nomutex(
simple_mutex_init(&msg_mutex, "Message mutex"); simple_mutex_init(&msg_mutex, "Message mutex");
#endif #endif
lm->lm_clientmes = skygw_message_init(); lm->lm_clientmes = skygw_message_init();
lm->lm_logmes = skygw_message_init(); lm->lm_logmes = skygw_message_init();
if (lm->lm_clientmes == NULL ||
lm->lm_logmes == NULL)
{
err = 1;
goto return_succp;
}
lm->lm_enabled_logfiles |= LOGFILE_ERROR; lm->lm_enabled_logfiles |= LOGFILE_ERROR;
lm->lm_enabled_logfiles |= LOGFILE_MESSAGE; lm->lm_enabled_logfiles |= LOGFILE_MESSAGE;
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
@ -390,7 +404,13 @@ static bool logmanager_init_nomutex(
fw->fwr_thread = skygw_thread_init("filewriter thr", fw->fwr_thread = skygw_thread_init("filewriter thr",
thr_filewriter_fun, thr_filewriter_fun,
(void *)fw); (void *)fw);
if (fw->fwr_thread == NULL)
{
err = 1;
goto return_succp;
}
if ((err = skygw_thread_start(fw->fwr_thread)) != 0) if ((err = skygw_thread_start(fw->fwr_thread)) != 0)
{ {
goto return_succp; goto return_succp;
@ -404,9 +424,12 @@ static bool logmanager_init_nomutex(
return_succp: return_succp:
if (err != 0) if (err != 0)
{ {
/** This releases memory of all created objects */ skygw_message_done(lm->lm_clientmes);
logmanager_done_nomutex(); skygw_message_done(lm->lm_logmes);
fprintf(stderr, "*\n* Error : Initializing log manager failed.\n*\n");
/** This releases memory of all created objects */
logmanager_done_nomutex();
fprintf(stderr, "*\n* Error : Initializing log manager failed.\n*\n");
} }
return succp; return succp;
} }

View File

@ -224,12 +224,20 @@ int skygw_rwlock_init(
int err; int err;
rwl = (skygw_rwlock_t *)calloc(1, sizeof(skygw_rwlock_t)); rwl = (skygw_rwlock_t *)calloc(1, sizeof(skygw_rwlock_t));
rwl->srw_chk_top = CHK_NUM_RWLOCK;
rwl->srw_chk_tail = CHK_NUM_RWLOCK; if (rwl == NULL)
err = pthread_rwlock_init(rwl->srw_rwlock, NULL); {
ss_dassert(err == 0); err = 1;
goto return_err;
if (err != 0) { }
rwl->srw_chk_top = CHK_NUM_RWLOCK;
rwl->srw_chk_tail = CHK_NUM_RWLOCK;
err = pthread_rwlock_init(rwl->srw_rwlock, NULL);
ss_dassert(err == 0);
if (err != 0)
{
free(rwl);
ss_dfprintf(stderr, ss_dfprintf(stderr,
"* Creating pthread_rwlock failed : %s\n", "* Creating pthread_rwlock failed : %s\n",
strerror(err)); strerror(err));
@ -1013,6 +1021,7 @@ skygw_thread_t* skygw_thread_init(
if (th->sth_mutex == NULL) { if (th->sth_mutex == NULL) {
thread_free_memory(th, th->sth_name); thread_free_memory(th, th->sth_name);
th = NULL;
goto return_th; goto return_th;
} }
th->sth_thrfun = sth_thrfun; th->sth_thrfun = sth_thrfun;
@ -1396,6 +1405,12 @@ skygw_message_t* skygw_message_init(void)
skygw_message_t* mes; skygw_message_t* mes;
mes = (skygw_message_t*)calloc(1, sizeof(skygw_message_t)); mes = (skygw_message_t*)calloc(1, sizeof(skygw_message_t));
if (mes == NULL)
{
err = 1;
goto return_mes;
}
mes->mes_chk_top = CHK_NUM_MESSAGE; mes->mes_chk_top = CHK_NUM_MESSAGE;
mes->mes_chk_tail = CHK_NUM_MESSAGE; mes->mes_chk_tail = CHK_NUM_MESSAGE;
err = pthread_mutex_init(&(mes->mes_mutex), NULL); err = pthread_mutex_init(&(mes->mes_mutex), NULL);
@ -1406,6 +1421,7 @@ skygw_message_t* skygw_message_init(void)
"%d, %s\n", "%d, %s\n",
err, err,
strerror(errno)); strerror(errno));
free(mes);
mes = NULL; mes = NULL;
goto return_mes; goto return_mes;
} }
@ -1417,6 +1433,8 @@ skygw_message_t* skygw_message_init(void)
"due error %d, %s\n", "due error %d, %s\n",
err, err,
strerror(errno)); strerror(errno));
pthread_mutex_destroy(&mes->mes_mutex);
free(mes);
mes = NULL; mes = NULL;
goto return_mes; goto return_mes;
} }