Răsfoiți Sursa

Fix a couple of memory leaks

The objdb occurred because object_find_destroy wasn't implemented!
 
The one in confdb occurred because object_find_destroy wasn't called if
object_find_next returned an error the first time it was invoked (ie
there were no subobjects).



git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1741 fd59a12c-fef9-0310-b244-a6a79926bd2f
Christine Caulfield 17 ani în urmă
părinte
comite
98cc132d48
3 a modificat fișierele cu 26 adăugiri și 7 ștergeri
  1. 18 1
      exec/objdb.c
  2. 1 1
      lib/confdb.c
  3. 7 5
      services/confdb.c

+ 18 - 1
exec/objdb.c

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2006 MontaVista Software, Inc.
- * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Copyright (c) 2007-2009 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -811,7 +811,24 @@ error_exit:
 static int object_find_destroy (
 	unsigned int object_find_handle)
 {
+	struct object_find_instance *object_find_instance;
+	unsigned int res;
+
+	objdb_rdlock();
+	res = hdb_handle_get (&object_find_instance_database,
+		object_find_handle, (void *)&object_find_instance);
+	if (res != 0) {
+		goto error_exit;
+	}
+	hdb_handle_put(&object_find_instance_database, object_find_handle);
+	hdb_handle_destroy(&object_find_instance_database, object_find_handle);
+
+	objdb_rdunlock();
 	return (0);
+
+error_exit:
+	objdb_rdunlock();
+	return (-1);
 }
 
 static int object_key_get (

+ 1 - 1
lib/confdb.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008 Red Hat, Inc.
+ * Copyright (c) 2008-2009 Red Hat, Inc.
  *
  * All rights reserved.
  *

+ 7 - 5
services/confdb.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008 Red Hat, Inc.
+ * Copyright (c) 2008-2009 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -326,8 +326,6 @@ static void message_handler_req_lib_confdb_object_find_destroy (void *conn, void
 	mar_res_header_t res;
 	int ret = CS_OK;
 
-	log_printf(LOG_LEVEL_DEBUG, "object_find_destroy for conn=%p, %d\n", conn, req_lib_confdb_object_find_destroy->find_handle);
-
 	if (api->object_find_destroy(req_lib_confdb_object_find_destroy->find_handle))
 		ret = CS_ERR_ACCESS;
 
@@ -523,8 +521,10 @@ static void message_handler_req_lib_confdb_object_iter (void *conn, void *messag
 		res_lib_confdb_object_iter.find_handle = req_lib_confdb_object_iter->find_handle;
 
 	if (api->object_find_next(res_lib_confdb_object_iter.find_handle,
-				  &res_lib_confdb_object_iter.object_handle))
+				  &res_lib_confdb_object_iter.object_handle)) {
 		ret = CS_ERR_ACCESS;
+		api->object_find_destroy(res_lib_confdb_object_iter.find_handle);
+	}
 	else {
 		api->object_name_get(res_lib_confdb_object_iter.object_handle,
 				     (char *)res_lib_confdb_object_iter.object_name.value,
@@ -555,8 +555,10 @@ static void message_handler_req_lib_confdb_object_find (void *conn, void *messag
 		res_lib_confdb_object_find.find_handle = req_lib_confdb_object_find->find_handle;
 
 	if (api->object_find_next(res_lib_confdb_object_find.find_handle,
-				  &res_lib_confdb_object_find.object_handle))
+				  &res_lib_confdb_object_find.object_handle)) {
 		ret = CS_ERR_ACCESS;
+		api->object_find_destroy(res_lib_confdb_object_find.find_handle);
+	}
 
 	res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find);
 	res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND;