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

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

Revision: 2120
Author:   ageric
Date:     2012-08-28 09:56:34 +0000 (Tue, 28 Aug 2012)
Log Message:
common/objects: Fix freeing contacts

Contacts used the 'i' variable when looping over objects, which
caused the iterator to jump up to seven the first time we iterated,
and then stay there for the remainder of the time. This triggered
a nasty bug where we'd go into "undefined behaviour" (often an
infinite loop or a coredump, as it turns out), when freeing contacts.

This bug only triggered when there was more than seven contacts in
total, which made it pretty hard to find at first.

The fix is simple though. We add a new iterator variable for the
contact addresses and use that when freeing them.

While at it, we remove an invalid free(), which was hidden by the
bug mentioned above.

Many thanks to Mike Guthrie and Ken Menzel who provided me with test
configs, as well as to Mark Frost who fixed the config anonymizer.

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

Modified Paths:

Modified: nagioscore/trunk/common/objects.c
--- nagioscore/trunk/common/objects.c	2012-08-28 09:56:16 UTC (rev 2119)
+++ nagioscore/trunk/common/objects.c	2012-08-28 09:56:34 UTC (rev 2120)
@@ -2664,6 +2664,7 @@
 	/**** free memory for the contact list ****/
 	for (i = 0; i < num_objects.contacts; i++) {
+		int j;
 		contact *this_contact = &contact_list[i];
 		/* free memory for the host notification commands */
@@ -2700,8 +2701,8 @@
-		for(i = 0; i < MAX_CONTACT_ADDRESSES; i++)
-			my_free(this_contact->address[i]);
+		for(j = 0; j < MAX_CONTACT_ADDRESSES; j++)
+			my_free(this_contact->address[j]);
 #ifdef NSCORE
@@ -2749,7 +2750,6 @@
 		this_contactsmember = this_service->contacts;
 		while(this_contactsmember != NULL) {
 			next_contactsmember = this_contactsmember->next;
-			my_free(this_contactsmember->contact_name);
 			this_contactsmember = next_contactsmember;

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