[Nagios-checkins] SF.net SVN: nagios:[2083] nagioscore/trunk/base/workers.c

ageric at users.sourceforge.net ageric at users.sourceforge.net
Tue Aug 21 09:55:09 UTC 2012


Revision: 2083
          http://nagios.svn.sourceforge.net/nagios/?rev=2083&view=rev
Author:   ageric
Date:     2012-08-21 09:55:09 +0000 (Tue, 21 Aug 2012)
Log Message:
-----------
core workers: Make sure we never free() any object names

Previously we used to copy service_description by assignment and
all other (well, contact_name and host_name) by strdup()'ing them,
but we free()'d all three.

Object names are seriously written in stone. Anything that changes
them or their pointers will mess with all sorts of interesting
containers (such as skiplists and hashtables), so we might as well
avoid strdup()'ing them and save ourselves the previously wasted
cycles while fixing the bug at the same time.

Reported-by: Robin Sonefors <robin.sonefors at op5.com>
Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/base/workers.c

Modified: nagioscore/trunk/base/workers.c
===================================================================
--- nagioscore/trunk/base/workers.c	2012-08-20 16:27:39 UTC (rev 2082)
+++ nagioscore/trunk/base/workers.c	2012-08-21 09:55:09 UTC (rev 2083)
@@ -115,14 +115,8 @@
 		free(job->arg);
 		break;
 	case WPJOB_NOTIFY:
-		free(oj->contact_name);
-		/* fallthrough */
 	case WPJOB_OCSP:
 	case WPJOB_OCHP:
-		free(oj->host_name);
-		if (oj->service_description) {
-			free(oj->service_description);
-		}
 		free(job->arg);
 		break;
 
@@ -697,9 +691,9 @@
 
 	oj = calloc(1, sizeof(*oj));
 	if (oj) {
-		oj->host_name = strdup(hname);
+		oj->host_name = hname;
 		if (cname)
-			oj->contact_name = strdup(cname);
+			oj->contact_name = cname;
 		if (sdesc)
 			oj->service_description = sdesc;
 	}

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