linux-ha CVS committal
Author : panjiam
Host : Project : linux-ha
Module : membership
Dir : linux-ha/membership/ccm
Modified Files:
ccmlib_clm.c ccmlib_eventapi.c
Log Message:
fixed memory leak and fd leak, bug # 858
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/membership/ccm/ccmlib_clm.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- ccmlib_clm.c 29 Jul 2005 23:02:03 -0000 1.11
+++ ccmlib_clm.c 30 Nov 2005 02:02:59 -0000 1.12
@@ -144,12 +144,14 @@
SaClmHandleT *hash_key;
fd_set rset;
struct timeval tv;
+ SaErrorT rc;
oc_ev_register(&ev_token);
if ((ret = oc_ev_set_callback(ev_token, OC_EV_MEMB_CLASS
, ccm_events, NULL)) != 0) {
if (ret == ENOMEM){
- return SA_ERR_NO_MEMORY;
+ rc = SA_ERR_NO_MEMORY;
+ goto err_nomem_exit;
}
else{
assert(0); /* Never runs here */
@@ -163,12 +165,15 @@
hash_key = (SaClmHandleT *)g_malloc(sizeof(SaClmHandleT));
if (!hash_key){
- return SA_ERR_NO_MEMORY;
+ rc = SA_ERR_NO_MEMORY;
+ goto err_nomem_exit;
}
hd = (__clm_handle_t *)g_malloc(sizeof(__clm_handle_t));
if (!hd){
- return SA_ERR_NO_MEMORY;
+ g_free(hash_key);
+ rc = SA_ERR_NO_MEMORY;
+ goto err_nomem_exit;
}
*clmHandle = __handle_counter++;
@@ -181,7 +186,8 @@
if ((ret = oc_ev_activate(hd->ev_token, &hd->fd)) != 0) {
cl_log(LOG_ERR, "oc_ev_activate error [%d]", ret);
- return SA_ERR_LIBRARY;
+ rc = SA_ERR_LIBRARY;
+ goto err_lib_exit;
}
/* Prepare information for saClmClusterNodeGet() series calls */
@@ -195,21 +201,33 @@
if ((ret = select(hd->fd + 1, &rset, NULL, NULL, &tv)) == -1) {
cl_log(LOG_ERR, "%s: select error [%d]"
, __FUNCTION__, ret);
- return SA_ERR_LIBRARY;
+ rc = SA_ERR_LIBRARY;
+ goto err_lib_exit;
} else if (ret == 0) {
cl_log(LOG_WARNING, "%s: select timeout", __FUNCTION__);
- return SA_ERR_TIMEOUT;
+ rc = SA_ERR_TIMEOUT;
+ goto err_lib_exit;
}
if ((ret = oc_ev_handle_event(hd->ev_token) != 0)) {
cl_log(LOG_ERR, "%s: oc_ev_handle_event error [%d]"
, __FUNCTION__, ret);
- return SA_ERR_LIBRARY;
+ rc = SA_ERR_LIBRARY;
+ goto err_lib_exit;
}
}
return SA_OK;
+
+ err_nomem_exit:
+ g_hash_table_remove(__handle_hash, hash_key);
+ g_free(hd);
+ g_free(hash_key);
+
+ err_lib_exit:
+ oc_ev_unregister(ev_token);
+ return rc;
}
SaErrorT
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/membership/ccm/ccmlib_eventapi.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- ccmlib_eventapi.c 29 Jul 2005 23:02:03 -0000 1.10
+++ ccmlib_eventapi.c 30 Nov 2005 02:02:59 -0000 1.11
@@ -1,4 +1,4 @@
-/* $Id: ccmlib_eventapi.c,v 1.10 2005/07/29 23:02:03 alan Exp $ */
+/* $Id: ccmlib_eventapi.c,v 1.11 2005/11/30 02:02:59 panjiam Exp $ */
/* * ccmlib_eventapi.c: OCF event API.
*
@@ -212,9 +212,13 @@
class_t *class = (class_t *)value;
/* if handle event fails, remove this class */
- if(!class->handle_event((void *)class))
- return TRUE;
-
+ if(!class->handle_event((void *)class)){
+ /* before we remove this class, + we
should unregister and free it first */
+ class->unregister(class);
+ g_free(class);
+ return TRUE;
+ }
/*do not remove this class*/
return FALSE;
}
_______________________________________________
Linux-ha-cvs mailing list
[email protected]
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs