fixed potential memleak;

v0.5.xx
Alexander Vdolainen 9 years ago
parent 2229c6f04c
commit e857badffd

@ -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) 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) 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; else if(idx_allocator_init(idx_msg, MAX_MSGINDEX, 0)) goto __fin_enomem;
if(!ch || !msg_tree) { if(!ch || !msg_tree) {
__fun_up2:
idx_allocator_destroy(idx_msg);
__fin_enomem: __fin_enomem:
r = ENOMEM; r = ENOMEM;
goto __fin_up; 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; ch->uuid = NULL;
usrtc_node_init(&ch->node, ch); usrtc_node_init(&ch->node, ch);
if(rlist) ch->rpc_list = rlist->rpc_list; if(rlist) ch->rpc_list = rlist->rpc_list;
else ch->rpc_list = NULL;
/* init locks */ /* init locks */
if(pthread_rwlock_init(&(ch->msglock), NULL)) { if(pthread_rwlock_init(&(ch->msglock), NULL)) {
r = ENOMEM; r = ENOMEM;
goto __fin_up; goto __fin_up2;
} }
if(pthread_mutex_init(&(ch->oplock), NULL)) { if(pthread_mutex_init(&(ch->oplock), NULL)) {
pthread_rwlock_destroy(&(ch->msglock)); pthread_rwlock_destroy(&(ch->msglock));
r = ENOMEM; r = ENOMEM;
goto __fin_up; goto __fin_up2;
} }
/* assign all the stuff */ /* assign all the stuff */
ch->idx_msg = idx_msg; ch->idx_msg = idx_msg;

Loading…
Cancel
Save