From e857badffd6624ce9795adb8cf0da9d9174588b6 Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Thu, 11 Jun 2015 03:52:30 +0300 Subject: [PATCH] fixed potential memleak; --- lib/channel.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/channel.c b/lib/channel.c index 278799f..665ed26 100644 --- a/lib/channel.c +++ b/lib/channel.c @@ -43,7 +43,7 @@ extern int __create_sys_msg(sxmsg_t **msg, char *uuid, chnl_t *ch, static long __cmp_ulong(const void *a, const void *b) { - return *(ulong_t *)a - *(ulong_t *)b; + return (long)(*(ulong_t *)a - *(ulong_t *)b); } int __alloc_channel(ulong_t cid, conn_t *co, rpc_typed_list_t *rlist, chnl_t **channel) @@ -57,6 +57,8 @@ int __alloc_channel(ulong_t cid, conn_t *co, rpc_typed_list_t *rlist, chnl_t **c else if(idx_allocator_init(idx_msg, MAX_MSGINDEX, 0)) goto __fin_enomem; if(!ch || !msg_tree) { + __fun_up2: + idx_allocator_destroy(idx_msg); __fin_enomem: r = ENOMEM; goto __fin_up; @@ -67,15 +69,16 @@ int __alloc_channel(ulong_t cid, conn_t *co, rpc_typed_list_t *rlist, chnl_t **c ch->uuid = NULL; usrtc_node_init(&ch->node, ch); if(rlist) ch->rpc_list = rlist->rpc_list; + else ch->rpc_list = NULL; /* init locks */ if(pthread_rwlock_init(&(ch->msglock), NULL)) { r = ENOMEM; - goto __fin_up; + goto __fin_up2; } if(pthread_mutex_init(&(ch->oplock), NULL)) { pthread_rwlock_destroy(&(ch->msglock)); r = ENOMEM; - goto __fin_up; + goto __fin_up2; } /* assign all the stuff */ ch->idx_msg = idx_msg;