[Nagios-checkins] SF.net SVN: nagios:[2119] nagioscore/trunk/common/objects.c

ageric at users.sourceforge.net ageric at users.sourceforge.net
Tue Aug 28 09:56:16 UTC 2012


Revision: 2119
          http://nagios.svn.sourceforge.net/nagios/?rev=2119&view=rev
Author:   ageric
Date:     2012-08-28 09:56:16 +0000 (Tue, 28 Aug 2012)
Log Message:
-----------
common/objects.c: Never free() objects taken from pre-allocated lists

Doing so will cause the entire block to be free()'d, and thus
invalid for future references. This was supposed to go in the
one-time allocation patch, but apparently I missed these back then.

Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/common/objects.c

Modified: nagioscore/trunk/common/objects.c
===================================================================
--- nagioscore/trunk/common/objects.c	2012-08-28 09:55:57 UTC (rev 2118)
+++ nagioscore/trunk/common/objects.c	2012-08-28 09:56:16 UTC (rev 2119)
@@ -943,7 +943,6 @@
 	if(result == ERROR) {
 		my_free(new_servicegroup->alias);
 		my_free(new_servicegroup->group_name);
-		my_free(new_servicegroup);
 		return NULL;
 		}
 
@@ -1130,7 +1129,6 @@
 		my_free(new_contact->alias);
 		my_free(new_contact->email);
 		my_free(new_contact->pager);
-		my_free(new_contact);
 		return NULL;
 		}
 
@@ -1504,7 +1502,6 @@
 		my_free(new_service->service_check_command);
 		my_free(new_service->description);
 		my_free(new_service->display_name);
-		my_free(new_service);
 		return NULL;
 		}
 
@@ -1789,7 +1786,6 @@
 	hostdependency *new_hostdependency = NULL;
 	host *parent, *child;
 	timeperiod *tp = NULL;
-	int result = OK;
 
 	/* make sure we have what we need */
 	parent = find_host(host_name);
@@ -1815,11 +1811,11 @@
 #ifndef NSCGI
 	if(dependency_type == NOTIFICATION_DEPENDENCY) {
 		if(add_object_to_objectlist(&child->notify_deps, new_hostdependency) != OK)
-			result = ERROR;
+			return NULL;
 		}
 	else {
 		if(add_object_to_objectlist(&child->exec_deps, new_hostdependency) != OK)
-			result = ERROR;
+			return NULL;
 		}
 
 	new_hostdependency->dependent_host_ptr = child;
@@ -1840,12 +1836,6 @@
 	new_hostdependency->fail_on_unreachable = (fail_on_unreachable == 1) ? TRUE : FALSE;
 	new_hostdependency->fail_on_pending = (fail_on_pending == 1) ? TRUE : FALSE;
 
-	/* handle errors */
-	if(result == ERROR) {
-		my_free(new_hostdependency);
-		return NULL;
-		}
-
 	new_hostdependency->id = num_objects.hostdependencies++;
 	if(new_hostdependency->id)
 		hostdependency_list[new_hostdependency->id - 1].next = new_hostdependency;

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Nagios-commits mailing list