diff -urN /home/exon/Nagios/base/Makefile.in ./base/Makefile.in
--- /home/exon/Nagios/base/Makefile.in	2004-11-05 15:18:45.000000000 +0100
+++ ./base/Makefile.in	2004-12-01 22:49:05.000000000 +0100
@@ -17,9 +17,9 @@
 #CFLAGS=-O3 -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -DHAVE_CONFIG_H -DNSCORE
 
 # Compiler flags for optimization (complements default)
-#CFLAGS_WARN=-Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs
-#CFLAGS_DEBUG=-ggdb3 -g3
-#CFLAGS+=$(CFLAGS_WARN) $(CFLAGS_DEBUG)
+CFLAGS_WARN=-Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs
+CFLAGS_DEBUG=-ggdb3 -g3 -DMEMLEAK_DEBUG
+CFLAGS+=$(CFLAGS_WARN) $(CFLAGS_DEBUG)
 
 LDFLAGS=@LDFLAGS@
 LIBS=@LIBS@
@@ -114,7 +114,7 @@
 DDATADEPS=$(DDATALIBS)
 
 
-OBJS=$(BROKER_O) checks.o config.o commands.o events.o flapping.o logging.o notifications.o sehandlers.o utils.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(DDATALIBS) $(BASEEXTRALIBS) $(SNPRINTF_O)
+OBJS=$(BROKER_O) memleak.o checks.o config.o commands.o events.o flapping.o logging.o notifications.o sehandlers.o utils.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(DDATALIBS) $(BASEEXTRALIBS) $(SNPRINTF_O)
 OBJDEPS=$(ODATADEPS) $(ODATADEPS) $(RDATADEPS) $(CDATADEPS) $(SDATADEPS) $(PDATADEPS) $(DDATADEPS) $(BROKER_H)
 
 all: nagios nagiostats
diff -urN /home/exon/Nagios/base/checks.c ./base/checks.c
--- /home/exon/Nagios/base/checks.c	2004-11-15 09:28:06.000000000 +0100
+++ ./base/checks.c	2004-12-01 22:46:51.000000000 +0100
@@ -1376,7 +1376,7 @@
 		return;
 
 	/* allocate memory for a new event item */
-	new_event=(timed_event *)malloc(sizeof(timed_event));
+	new_event=(timed_event *)mt_malloc(sizeof(timed_event));
 	if(new_event==NULL){
 
 		snprintf(temp_buffer,sizeof(temp_buffer),"Warning: Could not reschedule check of service '%s' on host '%s'!\n",svc->description,svc->host_name);
@@ -1423,12 +1423,12 @@
 
 		/* the originally queued event won the battle, so keep it and exit */
 		if(use_original_event==TRUE){
-			free(new_event);
+			mt_free(new_event);
 			return;
 		        }
 
 		remove_event(temp_event,&event_list_low);
-		free(temp_event);
+		mt_free(temp_event);
 	        }
 
 	/* set the next service check time */
@@ -2443,7 +2443,7 @@
 		return;
 
 	/* allocate memory for a new event item */
-	new_event=(timed_event *)malloc(sizeof(timed_event));
+	new_event=(timed_event *)mt_malloc(sizeof(timed_event));
 	if(new_event==NULL){
 
 		snprintf(temp_buffer,sizeof(temp_buffer),"Warning: Could not reschedule check of host '%s'!\n",hst->name);
@@ -2490,12 +2490,12 @@
 
 		/* the originally queued event won the battle, so keep it and exit */
 		if(use_original_event==TRUE){
-			free(new_event);
+			mt_free(new_event);
 			return;
 		        }
 
 		remove_event(temp_event,&event_list_low);
-		free(temp_event);
+		mt_free(temp_event);
 	        }
 
 	/* set the next host check time */
diff -urN /home/exon/Nagios/base/commands.c ./base/commands.c
--- /home/exon/Nagios/base/commands.c	2004-11-15 09:28:06.000000000 +0100
+++ ./base/commands.c	2004-12-01 22:46:51.000000000 +0100
@@ -140,7 +140,7 @@
 			strcpy(buffer,"");
 
 		/* free memory allocated for buffer slot */
-		free(((char **)external_command_buffer.buffer)[external_command_buffer.tail]);
+		mt_free(((char **)external_command_buffer.buffer)[external_command_buffer.tail]);
 
 		/* adjust tail counter and number of items */
 		external_command_buffer.tail=(external_command_buffer.tail + 1) % COMMAND_BUFFER_SLOTS;
@@ -1695,21 +1695,21 @@
 	temp_ptr=my_strtok(args,";");
 	if(temp_ptr==NULL)
 		return ERROR;
-	host_name=strdup(temp_ptr);
+	host_name=mt_strdup(temp_ptr);
 
 	/* get the service description */
 	temp_ptr=my_strtok(NULL,";");
 	if(temp_ptr==NULL){
-		free(host_name);
+		mt_free(host_name);
 		return ERROR;
 	        }
-	svc_description=strdup(temp_ptr);
+	svc_description=mt_strdup(temp_ptr);
 
 	/* get the service check return code */
 	temp_ptr=my_strtok(NULL,";");
 	if(temp_ptr==NULL){
-		free(host_name);
-		free(svc_description);
+		mt_free(host_name);
+		mt_free(svc_description);
 		return ERROR;
 	        }
 	return_code=atoi(temp_ptr);
@@ -1717,19 +1717,19 @@
 	/* get the plugin output */
 	temp_ptr=my_strtok(NULL,"\n");
 	if(temp_ptr==NULL){
-		free(host_name);
-		free(svc_description);
+		mt_free(host_name);
+		mt_free(svc_description);
 		return ERROR;
 	        }
-	output=strdup(temp_ptr);
+	output=mt_strdup(temp_ptr);
 
 	/* submit the passive check result */
 	result=process_passive_service_check(check_time,host_name,svc_description,return_code,output);
 
 	/* free memory */
-	free(host_name);
-	free(svc_description);
-	free(output);
+	mt_free(host_name);
+	mt_free(svc_description);
+	mt_free(output);
 
 #ifdef DEBUG0
 	printf("cmd_process_service_check_result() end\n");
@@ -1784,22 +1784,22 @@
 		return ERROR;
 
 	/* allocate memory for the passive check result */
-	new_pcr=(passive_check_result *)malloc(sizeof(passive_check_result));
+	new_pcr=(passive_check_result *)mt_malloc(sizeof(passive_check_result));
 	if(new_pcr==NULL)
 		return ERROR;
 
 	/* save the host name */
-	new_pcr->host_name=strdup(real_host_name);
+	new_pcr->host_name=mt_strdup(real_host_name);
 	if(new_pcr->host_name==NULL){
-		free(new_pcr);
+		mt_free(new_pcr);
 		return ERROR;
 	        }
 
 	/* save the service description */
-	new_pcr->svc_description=strdup(svc_description);
+	new_pcr->svc_description=mt_strdup(svc_description);
 	if(new_pcr->svc_description==NULL){
-		free(new_pcr->host_name);
-		free(new_pcr);
+		mt_free(new_pcr->host_name);
+		mt_free(new_pcr);
 		return ERROR;
 	        }
 
@@ -1811,11 +1811,11 @@
 		new_pcr->return_code=STATE_UNKNOWN;
 
 	/* save the output */
-	new_pcr->output=strdup(output);
+	new_pcr->output=mt_strdup(output);
 	if(new_pcr->output==NULL){
-		free(new_pcr->svc_description);
-		free(new_pcr->host_name);
-		free(new_pcr);
+		mt_free(new_pcr->svc_description);
+		mt_free(new_pcr->host_name);
+		mt_free(new_pcr);
 		return ERROR;
 	        }
 
@@ -1855,12 +1855,12 @@
 	temp_ptr=my_strtok(args,";");
 	if(temp_ptr==NULL)
 		return ERROR;
-	host_name=strdup(temp_ptr);
+	host_name=mt_strdup(temp_ptr);
 
 	/* get the host check return code */
 	temp_ptr=my_strtok(NULL,";");
 	if(temp_ptr==NULL){
-		free(host_name);
+		mt_free(host_name);
 		return ERROR;
 	        }
 	return_code=atoi(temp_ptr);
@@ -1868,17 +1868,17 @@
 	/* get the plugin output */
 	temp_ptr=my_strtok(NULL,"\n");
 	if(temp_ptr==NULL){
-		free(host_name);
+		mt_free(host_name);
 		return ERROR;
 	        }
-	output=strdup(temp_ptr);
+	output=mt_strdup(temp_ptr);
 
 	/* submit the check result */
 	result=process_passive_host_check(check_time,host_name,return_code,output);
 
 	/* free memory */
-	free(host_name);
-	free(output);
+	mt_free(host_name);
+	mt_free(output);
 
 #ifdef DEBUG0
 	printf("cmd_process_host_check_result() end\n");
@@ -2137,13 +2137,13 @@
 	temp_ptr=my_strtok(NULL,";");
 	if(temp_ptr==NULL)
 		return ERROR;
-	ack_author=strdup(temp_ptr);
+	ack_author=mt_strdup(temp_ptr);
 	
 	/* get the acknowledgement data */
 	temp_ptr=my_strtok(NULL,"\n");
 	if(temp_ptr==NULL)
 		return ERROR;
-	ack_data=strdup(temp_ptr);
+	ack_data=mt_strdup(temp_ptr);
 	
 	/* acknowledge the host problem */
 	if(cmd==CMD_ACKNOWLEDGE_HOST_PROBLEM)
@@ -2154,8 +2154,8 @@
 		acknowledge_service_problem(temp_service,ack_author,ack_data,type,notify,persistent);
 
 	/* free memory */
-	free(ack_author);
-	free(ack_data);
+	mt_free(ack_author);
+	mt_free(ack_data);
 
 #ifdef DEBUG0
 	printf("cmd_acknowledge_problem() end\n");
@@ -2498,7 +2498,7 @@
 
 	if(command_name==NULL)
 		return ERROR;
-	temp_ptr=strdup(command_name);
+	temp_ptr=mt_strdup(command_name);
 	if(temp_ptr==NULL)
 		return ERROR;
 
@@ -2511,42 +2511,42 @@
 	switch(cmd){
 
 	case CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER:
-		free(global_host_event_handler);
+		mt_free(global_host_event_handler);
 		global_host_event_handler=temp_ptr;
 		modified_host_process_attributes|=MODATTR_EVENT_HANDLER_COMMAND;
 		update_program_status(FALSE);
 		break;
 
 	case CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER:
-		free(global_service_event_handler);
+		mt_free(global_service_event_handler);
 		global_service_event_handler=temp_ptr;
 		modified_service_process_attributes|=MODATTR_EVENT_HANDLER_COMMAND;
 		update_program_status(FALSE);
 		break;
 
 	case CMD_CHANGE_HOST_EVENT_HANDLER:
-		free(temp_host->event_handler);
+		mt_free(temp_host->event_handler);
 		temp_host->event_handler=temp_ptr;
 		temp_host->modified_attributes|=MODATTR_EVENT_HANDLER_COMMAND;
 		update_host_status(temp_host,FALSE);
 		break;
 
 	case CMD_CHANGE_HOST_CHECK_COMMAND:
-		free(temp_host->host_check_command);
+		mt_free(temp_host->host_check_command);
 		temp_host->host_check_command=temp_ptr;
 		temp_host->modified_attributes|=MODATTR_CHECK_COMMAND;
 		update_host_status(temp_host,FALSE);
 		break;
 
 	case CMD_CHANGE_SVC_EVENT_HANDLER:
-		free(temp_service->event_handler);
+		mt_free(temp_service->event_handler);
 		temp_service->event_handler=temp_ptr;
 		temp_service->modified_attributes|=MODATTR_EVENT_HANDLER_COMMAND;
 		update_service_status(temp_service,FALSE);
 		break;
 
 	case CMD_CHANGE_SVC_CHECK_COMMAND:
-		free(temp_service->service_check_command);
+		mt_free(temp_service->service_check_command);
 		temp_service->service_check_command=temp_ptr;
 		temp_service->modified_attributes|=MODATTR_CHECK_COMMAND;
 		update_service_status(temp_service,FALSE);
@@ -2817,7 +2817,7 @@
 	/* we found a check event to remove */
 	if(temp_event!=NULL){
 		remove_event(temp_event,&event_list_low);
-		free(temp_event);
+		mt_free(temp_event);
 	        }
 
 	/* update the status log to reflect the new service state */
@@ -3769,7 +3769,7 @@
 	/* we found a check event to remove */
 	if(temp_event!=NULL){
 		remove_event(temp_event,&event_list_low);
-		free(temp_event);
+		mt_free(temp_event);
 	        }
 
 	/* update the status log with the host info */
@@ -4303,10 +4303,10 @@
 		this_pcr=passive_check_result_list;
 		while(this_pcr!=NULL){
 			next_pcr=this_pcr->next;
-			free(this_pcr->host_name);
-			free(this_pcr->svc_description);
-			free(this_pcr->output);
-			free(this_pcr);
+			mt_free(this_pcr->host_name);
+			mt_free(this_pcr->svc_description);
+			mt_free(this_pcr->output);
+			mt_free(this_pcr);
 			this_pcr=next_pcr;
 	                }
 
@@ -4321,10 +4321,10 @@
 	this_pcr=passive_check_result_list;
 	while(this_pcr!=NULL){
 		next_pcr=this_pcr->next;
-		free(this_pcr->host_name);
-		free(this_pcr->svc_description);
-		free(this_pcr->output);
-		free(this_pcr);
+		mt_free(this_pcr->host_name);
+		mt_free(this_pcr->svc_description);
+		mt_free(this_pcr->output);
+		mt_free(this_pcr);
 		this_pcr=next_pcr;
 	        }
 	passive_check_result_list=NULL;
diff -urN /home/exon/Nagios/base/config.c ./base/config.c
--- /home/exon/Nagios/base/config.c	2004-12-01 20:16:02.000000000 +0100
+++ ./base/config.c	2004-12-01 22:46:52.000000000 +0100
@@ -235,8 +235,8 @@
 
 	/* save the main config file macro */
 	if(macro_x[MACRO_MAINCONFIGFILE]!=NULL)
-		free(macro_x[MACRO_MAINCONFIGFILE]);
-	macro_x[MACRO_MAINCONFIGFILE]=(char *)strdup(main_config_file);
+		mt_free(macro_x[MACRO_MAINCONFIGFILE]);
+	macro_x[MACRO_MAINCONFIGFILE]=(char *)mt_strdup(main_config_file);
 	if(macro_x[MACRO_MAINCONFIGFILE]!=NULL)
 		strip(macro_x[MACRO_MAINCONFIGFILE]);
 
@@ -245,7 +245,7 @@
 
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -306,8 +306,8 @@
 
 			/* save the macro */
 			if(macro_x[MACRO_RESOURCEFILE]!=NULL)
-				free(macro_x[MACRO_RESOURCEFILE]);
-			macro_x[MACRO_RESOURCEFILE]=(char *)strdup(value);
+				mt_free(macro_x[MACRO_RESOURCEFILE]);
+			macro_x[MACRO_RESOURCEFILE]=(char *)mt_strdup(value);
 			if(macro_x[MACRO_RESOURCEFILE]==NULL){
 				strcpy(error_message,"Could not allocate memory for macro");
 				error=TRUE;
@@ -329,14 +329,14 @@
 				}
 
 			if(log_file!=NULL)
-				free(log_file);
-			log_file=(char *)strdup(value);
+				mt_free(log_file);
+			log_file=(char *)mt_strdup(value);
 			strip(log_file);
 
 			/* save the macro */
 			if(macro_x[MACRO_LOGFILE]!=NULL)
-				free(macro_x[MACRO_LOGFILE]);
-			macro_x[MACRO_LOGFILE]=(char *)strdup(log_file);
+				mt_free(macro_x[MACRO_LOGFILE]);
+			macro_x[MACRO_LOGFILE]=(char *)mt_strdup(log_file);
 			if(macro_x[MACRO_LOGFILE]==NULL){
 				strcpy(error_message,"Could not allocate memory for macro");
 				error=TRUE;
@@ -356,14 +356,14 @@
 				}
 
 			if(command_file!=NULL)
-				free(command_file);
-			command_file=(char *)strdup(value);
+				mt_free(command_file);
+			command_file=(char *)mt_strdup(value);
 			strip(command_file);
 
 			/* save the macro */
 			if(macro_x[MACRO_COMMANDFILE]!=NULL)
-				free(macro_x[MACRO_COMMANDFILE]);
-			macro_x[MACRO_COMMANDFILE]=(char *)strdup(value);
+				mt_free(macro_x[MACRO_COMMANDFILE]);
+			macro_x[MACRO_COMMANDFILE]=(char *)mt_strdup(value);
 			if(macro_x[MACRO_COMMANDFILE]==NULL){
 				strcpy(error_message,"Could not allocate memory for macro");
 				error=TRUE;
@@ -384,14 +384,14 @@
 				}
 
 			if(temp_file!=NULL)
-				free(temp_file);
-			temp_file=(char *)strdup(value);
+				mt_free(temp_file);
+			temp_file=(char *)mt_strdup(value);
 			strip(temp_file);
 
 			/* save the macro */
 			if(macro_x[MACRO_TEMPFILE]!=NULL)
-				free(macro_x[MACRO_TEMPFILE]);
-			macro_x[MACRO_TEMPFILE]=(char *)strdup(temp_file);
+				mt_free(macro_x[MACRO_TEMPFILE]);
+			macro_x[MACRO_TEMPFILE]=(char *)mt_strdup(temp_file);
 			if(macro_x[MACRO_TEMPFILE]==NULL){
 				strcpy(error_message,"Could not allocate memory for macro");
 				error=TRUE;
@@ -411,8 +411,8 @@
 				}
 
 			if(lock_file!=NULL)
-				free(lock_file);
-			lock_file=(char *)strdup(value);
+				mt_free(lock_file);
+			lock_file=(char *)mt_strdup(value);
 			strip(lock_file);
 
 #ifdef DEBUG1
@@ -421,8 +421,8 @@
 			}
 		else if(!strcmp(variable,"global_host_event_handler")){
 			if(global_host_event_handler!=NULL)
-				free(global_host_event_handler);
-			global_host_event_handler=(char *)strdup(value);
+				mt_free(global_host_event_handler);
+			global_host_event_handler=(char *)mt_strdup(value);
 			if(global_host_event_handler==NULL){
 				strcpy(error_message,"Could not allocate memory for global host event handler");
 				error=TRUE;
@@ -436,8 +436,8 @@
 		        }
 		else if(!strcmp(variable,"global_service_event_handler")){
 			if(global_service_event_handler!=NULL)
-				free(global_service_event_handler);
-			global_service_event_handler=(char *)strdup(value);
+				mt_free(global_service_event_handler);
+			global_service_event_handler=(char *)mt_strdup(value);
 			if(global_service_event_handler==NULL){
 				strcpy(error_message,"Could not allocate memory for global service event handler");
 				error=TRUE;
@@ -452,8 +452,8 @@
 		        }
 		else if(!strcmp(variable,"ocsp_command")){
 			if(ocsp_command!=NULL)
-				free(ocsp_command);
-			ocsp_command=(char *)strdup(value);
+				mt_free(ocsp_command);
+			ocsp_command=(char *)mt_strdup(value);
 			if(ocsp_command==NULL){
 				strcpy(error_message,"Could not allocate memory for obsessive compulsive service processor command");
 				error=TRUE;
@@ -468,8 +468,8 @@
 		        }
 		else if(!strcmp(variable,"ochp_command")){
 			if(ochp_command!=NULL)
-				free(ochp_command);
-			ochp_command=(char *)strdup(value);
+				mt_free(ochp_command);
+			ochp_command=(char *)mt_strdup(value);
 			if(ochp_command==NULL){
 				strcpy(error_message,"Could not allocate memory for obsessive compulsive host processor command");
 				error=TRUE;
@@ -484,8 +484,8 @@
 		        }
 		else if(!strcmp(variable,"nagios_user")){
 			if(nagios_user!=NULL)
-				free(nagios_user);
-			nagios_user=(char *)strdup(value);
+				mt_free(nagios_user);
+			nagios_user=(char *)mt_strdup(value);
 			if(nagios_user==NULL){
 				strcpy(error_message,"Could not allocate memory for nagios user");
 				error=TRUE;
@@ -500,8 +500,8 @@
 		        }
 		else if(!strcmp(variable,"nagios_group")){
 			if(nagios_group!=NULL)
-				free(nagios_group);
-			nagios_group=(char *)strdup(value);
+				mt_free(nagios_group);
+			nagios_group=(char *)mt_strdup(value);
 			if(nagios_group==NULL){
 				strcpy(error_message,"Could not allocate memory for nagios group");
 				error=TRUE;
@@ -518,8 +518,8 @@
 
 			/* save the macro */
 			if(macro_x[MACRO_ADMINEMAIL]!=NULL)
-				free(macro_x[MACRO_ADMINEMAIL]);
-			macro_x[MACRO_ADMINEMAIL]=(char *)strdup(value);
+				mt_free(macro_x[MACRO_ADMINEMAIL]);
+			macro_x[MACRO_ADMINEMAIL]=(char *)mt_strdup(value);
 			if(macro_x[MACRO_ADMINEMAIL]==NULL){
 				strcpy(error_message,"Could not allocate memory for admin email address");
 				error=TRUE;
@@ -536,8 +536,8 @@
 
 			/* save the macro */
 			if(macro_x[MACRO_ADMINPAGER]!=NULL)
-				free(macro_x[MACRO_ADMINPAGER]);
-			macro_x[MACRO_ADMINPAGER]=(char *)strdup(value);
+				mt_free(macro_x[MACRO_ADMINPAGER]);
+			macro_x[MACRO_ADMINPAGER]=(char *)mt_strdup(value);
 			if(macro_x[MACRO_ADMINPAGER]==NULL){
 				strcpy(error_message,"Could not allocate memory for admin pager");
 				error=TRUE;
@@ -901,8 +901,8 @@
 				}
 
 			if(log_archive_path!=NULL)
-				free(log_archive_path);
-			log_archive_path=(char *)strdup(value);
+				mt_free(log_archive_path);
+			log_archive_path=(char *)mt_strdup(value);
 			strip(log_archive_path);
 
 #ifdef DEBUG1
@@ -1350,8 +1350,8 @@
 				}
 
 			if(p1_file!=NULL)
-				free(p1_file);
-			p1_file=(char *)strdup(value);
+				mt_free(p1_file);
+			p1_file=(char *)mt_strdup(value);
 			strip(p1_file);
 
 #ifdef DEBUG1
@@ -1368,13 +1368,13 @@
 #endif
 		        }
 		else if(!strcmp(variable,"illegal_object_name_chars")){
-			illegal_object_chars=strdup(value);
+			illegal_object_chars=mt_strdup(value);
 #ifdef DEBUG1
 			printf("\t\tillegal_object_name_chars set to '%s'\n",illegal_object_chars);
 #endif
 		        }
 		else if(!strcmp(variable,"illegal_macro_output_chars")){
-			illegal_output_chars=strdup(value);
+			illegal_output_chars=mt_strdup(value);
 #ifdef DEBUG1
 			printf("\t\tillegal_macro_output_chars set to '%s'\n",illegal_output_chars);
 #endif
@@ -1410,8 +1410,8 @@
 			        }
 
 			if(auth_file!=NULL)
-				free(auth_file);
-			auth_file=(char *)strdup(value);
+				mt_free(auth_file);
+			auth_file=(char *)mt_strdup(value);
 			strip(auth_file);
 #ifdef DEBUG1
 			printf("\t\tauth_file set to '%s'\n",auth_file);
@@ -1459,7 +1459,7 @@
 	        }
 
 	/* free leftover memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	/* make sure a log file has been specified */
@@ -1510,7 +1510,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -1567,8 +1567,8 @@
 				user_index=atoi(variable+5)-1;
 				if(user_index>=0 && user_index<MAX_USER_MACROS){
 					if(macro_user[user_index]!=NULL)
-						free(macro_user[user_index]);
-					macro_user[user_index]=strdup(value);
+						mt_free(macro_user[user_index]);
+					macro_user[user_index]=mt_strdup(value);
 					if(macro_user[user_index]!=NULL){
 						strcpy(macro_user[user_index],value);
 #ifdef DEBUG1
@@ -1581,7 +1581,7 @@
 	        }
 
 	/* free leftover memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	if(error==TRUE)
diff -urN /home/exon/Nagios/base/events.c ./base/events.c
--- /home/exon/Nagios/base/events.c	2004-12-01 20:16:02.000000000 +0100
+++ ./base/events.c	2004-12-01 22:46:52.000000000 +0100
@@ -676,7 +676,7 @@
 	else
 		event_list=&event_list_low;
 
-	new_event=(timed_event *)malloc(sizeof(timed_event));
+	new_event=(timed_event *)mt_malloc(sizeof(timed_event));
 	if(new_event!=NULL){
 		new_event->event_type=event_type;
 		new_event->event_data=event_data;
@@ -917,7 +917,7 @@
 
 			/* else free memory associated with the event */
 			else
-				free(temp_event);
+				mt_free(temp_event);
 		        }
 
 		/* handle low priority events */
@@ -1021,7 +1021,7 @@
 
 				/* else free memory associated with the event */
 				else
-					free(temp_event);
+					mt_free(temp_event);
 			        }
 
 			/* wait a while so we don't hog the CPU... */
diff -urN /home/exon/Nagios/base/memleak.c ./base/memleak.c
--- /home/exon/Nagios/base/memleak.c	1970-01-01 01:00:00.000000000 +0100
+++ ./base/memleak.c	2004-12-03 00:18:41.000000000 +0100
@@ -0,0 +1,299 @@
+/*
+ * $Id: $
+ *
+ * An attempt to catch memory leaks in a running Nagios process
+ * (crude garbage-collector, basically)
+ *
+ */
+
+#include "../include/memleak.h"
+#ifdef MEMLEAK_DEBUG
+
+#define LEAK_LOG "/tmp/nagios.leak"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+
+#define MAX_MSG_SIZE	256
+
+struct mem_tracker {
+	void *ptr;
+	size_t len;
+	unsigned int flag;
+	struct mem_tracker *next, *prev;
+};
+
+char *mt_flags[] = { "free()", "malloc()", "realloc()", "strdup()", "realloc() used as malloc() (called with NULL pointer)", "** realloc() failed! **", NULL };
+
+/* not used outside of this file */
+static struct mem_tracker *mt;
+static struct mem_tracker *mt_base;
+static FILE *leak_file = stdout;
+static unsigned long mt_items = 0;
+static unsigned long mt_total = 0;
+
+/* these are all ordered properly, so we don't need prototypes */
+/* static void leak_log(const char *, ...); */
+/* static void dump_mt_status(void); */
+/* static void add_mt(void *, size_t, int); */
+/* static void del_mt(void *); */
+
+/* various flag settings */
+#define MT_FREE 0
+#define MT_MALLOC 1
+#define MT_REALLOC 2
+#define MT_STRDUP 3
+#define MT_REALLOC_AS_MALLOC 4
+#define MT_REALLOC_ABANDONED 5
+#define MT_LOG_SELF 6
+#define MT_FLAG_OOB 7
+
+/* log any arbitrary message to the leak_log file */
+static void leak_log(const char *format, ...)
+{
+	va_list ap, aq;
+	int d, i = 0, p;
+	int len;
+	char c, *s;
+	char nums[22];	/* 8 bits width holds room for 18446744073709551616 (22 chars, including '\0') */
+	char msg[MAX_MSG_SIZE];
+	char *fmt;
+
+	len = strlen(format);
+	if(!len) return;
+	va_start(ap, format);
+
+	memset(msg, 0, MAX_MSG_SIZE);
+
+	aq = ap;
+	for(p=0; p<len; p++) {
+		if(i >= MAX_MSG_SIZE - 1) break;
+		fmt = &format[p];
+		/* catch non-format characters. only go to switch() if have to */
+		if(!p || *(fmt-1) != '%') {
+			if(*fmt != '%') msg[i++] = *fmt;
+			continue;
+		}
+		switch(*fmt) {
+			case 's':
+				s = va_arg(ap, char *);
+				if(strlen(s) > MAX_MSG_SIZE - i) {
+					s[MAX_MSG_SIZE - i] = '\0';
+				}
+				strcat(&msg[i], s);
+				i += strlen(s);
+				break;
+			case 'd':
+			case 'u':
+			case 'p':
+				/* the only difference here is a typecast in
+				 * the sprintf call, so we bungle the two */
+				/* also take the trouble to invoke sprintf to nums
+				 * first to safeguard against BoF's while sticking
+				 * to strict ANSI C */
+				memset(nums, 0, 22);
+				d = va_arg(ap, int);
+				if(*fmt == 'd') sprintf(nums, "%d", (int)d);
+				else if(*fmt == 'u') sprintf(nums, "%u", (unsigned int)d);
+				else sprintf(nums, "%p", (void *)d);
+				strncat(&msg[i], nums, MAX_MSG_SIZE - (i+1));
+				i += strlen(nums);
+				break;
+			case 'c':
+				c = (char)va_arg(ap, int);
+				msg[i++] = c;
+				break;
+			case '%':
+				msg[i++] = '%';
+				break;
+		}
+	}
+	va_end(ap);
+	msg[i] = '\0';
+
+	/* let's hope this doesn't fail */
+	leak_file = fopen(LEAK_LOG, "a");
+	fprintf(leak_file, "%s\n", msg);
+	fclose(leak_file);
+
+}
+
+void dump_mt_status(void) {
+	struct mem_tracker *m;
+	unsigned long total = 0, items = 0;
+
+	/* avoid division by zero and silly output */
+	if(!mt_items) return;
+
+	leak_log(" ");
+	for(m = mt_base->next; m->next != NULL; m = m->next) {
+		total += m->len;
+		items++;
+		leak_log("# %p : %u; %s", m->ptr, m->len, mt_flags[m->flag]);
+	}
+
+	leak_log("** %u bytes in %u vars. average size ~ %u",
+			 total, items, total / items);
+	leak_log("** (runtime counter) %u bytes in %u vars. average size ~ %u",
+			 mt_total, mt_items, mt_total / mt_items);
+	leak_log(" ");
+}
+
+static void add_mt(void *ptr, size_t len, int flag) {
+	struct mem_tracker *m;
+
+	mt_items++;
+	mt_total += len;
+
+	/* this WILL leak 1*sizeof(struct mem_tracker) */
+	if(!mt_base) {
+		/* If the garbage collector leaks, we lose.
+		 * If it can't malloc, we're gonna crash and burn */
+		mt_base = malloc(sizeof(struct mem_tracker));
+		if(!mt_base) leak_log("Can't malloc mt_base!");
+		mt = mt_base;
+		mt->len = 0;
+		mt->flag = 0;
+		mt->prev = NULL;
+		mt->ptr = NULL;
+		mt->next = malloc(sizeof(struct mem_tracker));
+		mt_base = mt->next;
+	}
+
+	m = mt;
+	mt = mt->next;
+
+	mt->prev = m;
+	mt->ptr = ptr;
+	mt->len = len;
+	mt->flag = 0;
+	mt->next = malloc(sizeof(struct mem_tracker));
+	mt->next->prev = mt;
+
+	if(flag == MT_LOG_SELF) return;
+
+	mt->flag = flag;
+	leak_log("+ %p : %u; %s # Bytes: %u, Items: %u, Avg: ~ %u",
+			 ptr, len, mt_flags[flag],
+			 mt_total, mt_items, mt_total / mt_items);
+}
+
+static void del_mt(void *ptr) {
+	struct mem_tracker *m;
+	unsigned long i = 0;
+
+	/* protect against NULL free's. This is the only concession we do
+	 * to poor memory management right now */
+	if(!ptr) {
+		leak_log("! free() called on NULL pointer\n");
+		return;
+	}
+
+	for(m = mt_base; m->next != NULL; m = m->next) {
+		i++;
+		if(m && m->ptr == ptr) break;
+	}
+
+	if(!m && i > mt_items) {
+		leak_log("!! %p : tracker borked. del_mt() called with impossible pointer. i: %u; mt_items: %u",
+				 ptr, i, mt_items);
+		dump_mt_status();
+		return;
+	}
+
+	if(!m && i == mt_items) {
+		leak_log("! %p : possible double free", ptr);
+		return;
+	}
+
+	/* step down the totals count */
+	mt_total -= m->len;
+	mt_items--;
+
+	leak_log("- %p : %u; %s # Bytes: %u, Items: %u, Avg: ~ %u",
+			 m->ptr, m->len, mt_flags[m->flag],
+			 mt_total, mt_items, mt_total / mt_items);
+
+	/* remove and free this entry */
+	m->prev->next = m->next;
+	m->next->prev = m->prev;
+	free(m);
+
+	/* now reset mt */
+	for(mt = mt_base; mt->next != NULL; mt = mt->next) ;
+}
+
+
+/*
+ * the tracker functions
+ */
+void *mt_malloc(size_t len) {
+	void *ptr;
+
+	if((ptr = malloc(len)) != NULL) {
+		add_mt(ptr, len, MT_MALLOC);
+	}
+
+	return ptr;
+}
+
+void *mt_realloc(void *orig_ptr, size_t len) {
+	void *ptr;
+
+	if(orig_ptr == NULL) {
+		ptr = malloc(len);
+		add_mt(ptr, len, MT_REALLOC_AS_MALLOC);
+		return ptr;
+	}
+
+	ptr = realloc(orig_ptr, len);
+	del_mt(orig_ptr);
+	add_mt(ptr, len, MT_LOG_SELF);
+	leak_log("+ %p : %u (realloc(%p, %u))", ptr, len, orig_ptr, len);
+
+	return ptr;
+}
+
+char *mt_strdup(const char *src) {
+	char *dest;
+
+	dest = strdup(src);
+	add_mt(dest, strlen(src), MT_STRDUP);
+
+	return dest;
+}
+
+void mt_free(void *ptr) {
+	del_mt(ptr);
+	free(ptr);
+}
+
+/* Use this to debug the memtracker */
+/*
+int main(int argc, char **argv) {
+	int i;
+	char *str, *s, *p;
+	int tot = 0;
+
+	str = s = p = NULL;
+	for(i = 0; i < argc; i++) {
+		if(!i) p = mt_strdup(argv[i]);
+		else if(argc / 2 == i) s = mt_strdup(argv[i]);
+
+		tot += strlen(argv[i]);
+
+		str = mt_strdup(argv[i]);
+		str = (void *)mt_malloc((i+1) * strlen(argv[i]));
+	}
+
+	mt_free(p);
+	mt_free(str);
+
+	dump_mt_status();
+
+	return 0;
+}
+*/
+#endif
diff -urN /home/exon/Nagios/base/nagios.c ./base/nagios.c
--- /home/exon/Nagios/base/nagios.c	2004-11-05 15:18:45.000000000 +0100
+++ ./base/nagios.c	2004-12-01 22:46:52.000000000 +0100
@@ -339,7 +339,7 @@
 
 
 	/* config file is last argument specified */
-	config_file=(char *)strdup(argv[optind]);
+	config_file=(char *)mt_strdup(argv[optind]);
 	if(config_file==NULL){
 		printf("Error allocating memory.\n");
 		exit(ERROR);
@@ -353,7 +353,7 @@
 		buffer[sizeof(buffer)-1]='\x0';
 
 		/* reallocate a larger chunk of memory */
-		config_file=(char *)realloc(config_file,MAX_FILENAME_LENGTH);
+		config_file=(char *)mt_realloc(config_file,MAX_FILENAME_LENGTH);
 		if(config_file==NULL){
 			printf("Error allocating memory.\n");
 			exit(ERROR);
@@ -718,7 +718,7 @@
 	                }while(sigrestart==TRUE && sigshutdown==FALSE);
 
 		/* free misc memory */
-		free(config_file);
+		mt_free(config_file);
 	        }
 
 	return OK;
diff -urN /home/exon/Nagios/base/nagiostats.c ./base/nagiostats.c
--- /home/exon/Nagios/base/nagiostats.c	2004-11-05 15:18:45.000000000 +0100
+++ ./base/nagiostats.c	2004-12-01 22:46:52.000000000 +0100
@@ -203,7 +203,7 @@
 			mrtg_mode=TRUE;
 			break;
 		case 'd':
-			mrtg_variables=strdup(optarg);
+			mrtg_variables=mt_strdup(optarg);
 			break;
 
 		default:
@@ -865,7 +865,7 @@
 				if(!strcmp(var,"created"))
 					status_creation_date=strtoul(val,NULL,10);
 				else if(!strcmp(var,"version"))
-					status_version=strdup(val);
+					status_version=mt_strdup(val);
 				break;
 
 			case STATUS_PROGRAM_DATA:
diff -urN /home/exon/Nagios/base/nebmods.c ./base/nebmods.c
--- /home/exon/Nagios/base/nebmods.c	2004-11-05 15:18:45.000000000 +0100
+++ ./base/nebmods.c	2004-12-01 22:46:52.000000000 +0100
@@ -83,13 +83,13 @@
 		return ERROR;
 
 	/* allocate memory */
-	new_module=(nebmodule *)malloc(sizeof(nebmodule));
+	new_module=(nebmodule *)mt_malloc(sizeof(nebmodule));
 	if(new_module==NULL)
 		return ERROR;
 
 	/* initialize vars */
-	new_module->filename=(char *)strdup(filename);
-	new_module->args=(args==NULL)?NULL:(char *)strdup(args);
+	new_module->filename=(char *)mt_strdup(filename);
+	new_module->args=(args==NULL)?NULL:(char *)mt_strdup(args);
 	new_module->should_be_loaded=should_be_loaded;
 	new_module->is_currently_loaded=FALSE;
 	for(x=0;x<NEBMODULE_MODINFO_NUMITEMS;x++)
@@ -119,11 +119,11 @@
 
 	for(temp_module=neb_module_list;temp_module;){
 		next_module=temp_module->next;
-		free(temp_module->filename);
-		free(temp_module->args);
+		mt_free(temp_module->filename);
+		mt_free(temp_module->args);
 		for(x=0;x<NEBMODULE_MODINFO_NUMITEMS;x++)
-			free(temp_module->info[x]);
-		free(temp_module);
+			mt_free(temp_module->info[x]);
+		mt_free(temp_module);
 		temp_module=next_module;
 	        }
 
@@ -363,13 +363,13 @@
 	mod=(nebmodule *)handle;
 
 	/* free any previously allocated memory */
-	free(mod->info[type]);
+	mt_free(mod->info[type]);
 
 	/* allocate memory for the new data */
 	if(data==NULL)
 		mod->info[type]=NULL;
 	else{
-		mod->info[type]=strdup(data);
+		mod->info[type]=mt_strdup(data);
 		if(mod->info[type]==NULL)
 			return NEBERROR_NOMEM;
 	        }
@@ -402,7 +402,7 @@
 		return NEBERROR_CALLBACKBOUNDS;
 
 	/* allocate memory */
-	new_callback=(nebcallback *)malloc(sizeof(nebcallback));
+	new_callback=(nebcallback *)mt_malloc(sizeof(nebcallback));
 	if(new_callback==NULL)
 		return NEBERROR_NOMEM;
 	
@@ -469,7 +469,7 @@
 
 	else{
 		last_callback->next=next_callback;
-		free(temp_callback);
+		mt_free(temp_callback);
 	        }
 	
 	return OK;
@@ -510,7 +510,7 @@
 	int x;
 
 	/* allocate memory for the callback list */
-	neb_callback_list=(nebcallback **)malloc(NEBCALLBACK_NUMITEMS*sizeof(nebcallback *));
+	neb_callback_list=(nebcallback **)mt_malloc(NEBCALLBACK_NUMITEMS*sizeof(nebcallback *));
 	if(neb_callback_list==NULL)
 		return ERROR;
 
@@ -532,14 +532,14 @@
 
 		for(temp_callback=neb_callback_list[x];temp_callback!=NULL;temp_callback=next_callback){
 			next_callback=temp_callback->next;
-			free(temp_callback);
+			mt_free(temp_callback);
 			temp_callback=next_callback;
 	                }
 
 		neb_callback_list[x]=NULL;
 	        }
 
-	free(neb_callback_list);
+	mt_free(neb_callback_list);
 	neb_callback_list=NULL;
 
 	return OK;
diff -urN /home/exon/Nagios/base/notifications.c ./base/notifications.c
--- /home/exon/Nagios/base/notifications.c	2004-11-15 09:28:06.000000000 +0100
+++ ./base/notifications.c	2004-12-01 22:46:52.000000000 +0100
@@ -124,23 +124,23 @@
 		/* if this is an acknowledgement, get the acknowledgement macros */
 		if(type==NOTIFICATION_ACKNOWLEDGEMENT){
 			if(macro_x[MACRO_SERVICEACKAUTHOR]!=NULL)
-				free(macro_x[MACRO_SERVICEACKAUTHOR]);
+				mt_free(macro_x[MACRO_SERVICEACKAUTHOR]);
 			if(ack_author==NULL)
 				macro_x[MACRO_SERVICEACKAUTHOR]=NULL;
 			else
-				macro_x[MACRO_SERVICEACKAUTHOR]=strdup(ack_author);
+				macro_x[MACRO_SERVICEACKAUTHOR]=mt_strdup(ack_author);
 			if(macro_x[MACRO_SERVICEACKCOMMENT]!=NULL)
-				free(macro_x[MACRO_SERVICEACKCOMMENT]);
+				mt_free(macro_x[MACRO_SERVICEACKCOMMENT]);
 			if(ack_data==NULL)
 				macro_x[MACRO_SERVICEACKCOMMENT]=NULL;
 			else
-				macro_x[MACRO_SERVICEACKCOMMENT]=strdup(ack_data);
+				macro_x[MACRO_SERVICEACKCOMMENT]=mt_strdup(ack_data);
 	                }
 
 		/* set the notification type macro */
 		if(macro_x[MACRO_NOTIFICATIONTYPE]!=NULL)
-			free(macro_x[MACRO_NOTIFICATIONTYPE]);
-		macro_x[MACRO_NOTIFICATIONTYPE]=(char *)malloc(MAX_NOTIFICATIONTYPE_LENGTH);
+			mt_free(macro_x[MACRO_NOTIFICATIONTYPE]);
+		macro_x[MACRO_NOTIFICATIONTYPE]=(char *)mt_malloc(MAX_NOTIFICATIONTYPE_LENGTH);
 		if(macro_x[MACRO_NOTIFICATIONTYPE]!=NULL){
 			if(type==NOTIFICATION_ACKNOWLEDGEMENT)
 				strcpy(macro_x[MACRO_NOTIFICATIONTYPE],"ACKNOWLEDGEMENT");
@@ -156,8 +156,8 @@
 
 		/* set the notification number macro */
 		if(macro_x[MACRO_NOTIFICATIONNUMBER]!=NULL)
-			free(macro_x[MACRO_NOTIFICATIONNUMBER]);
-		macro_x[MACRO_NOTIFICATIONNUMBER]=(char *)malloc(MAX_NOTIFICATIONNUMBER_LENGTH);
+			mt_free(macro_x[MACRO_NOTIFICATIONNUMBER]);
+		macro_x[MACRO_NOTIFICATIONNUMBER]=(char *)mt_malloc(MAX_NOTIFICATIONNUMBER_LENGTH);
 		if(macro_x[MACRO_NOTIFICATIONNUMBER]!=NULL){
 			snprintf(macro_x[MACRO_NOTIFICATIONNUMBER],MAX_NOTIFICATIONNUMBER_LENGTH-1,"%d",svc->current_notification_number);
 			macro_x[MACRO_NOTIFICATIONNUMBER][MAX_NOTIFICATIONNUMBER_LENGTH-1]='\x0';
@@ -877,23 +877,23 @@
 		/* if this is an acknowledgement, get the acknowledgement macros */
 		if(type==NOTIFICATION_ACKNOWLEDGEMENT){
 			if(macro_x[MACRO_HOSTACKAUTHOR]!=NULL)
-				free(macro_x[MACRO_HOSTACKAUTHOR]);
+				mt_free(macro_x[MACRO_HOSTACKAUTHOR]);
 			if(ack_author==NULL)
 				macro_x[MACRO_HOSTACKAUTHOR]=NULL;
 			else
-				macro_x[MACRO_HOSTACKAUTHOR]=strdup(ack_author);
+				macro_x[MACRO_HOSTACKAUTHOR]=mt_strdup(ack_author);
 			if(macro_x[MACRO_HOSTACKCOMMENT]!=NULL)
-				free(macro_x[MACRO_HOSTACKCOMMENT]);
+				mt_free(macro_x[MACRO_HOSTACKCOMMENT]);
 			if(ack_data==NULL)
 				macro_x[MACRO_HOSTACKCOMMENT]=NULL;
 			else
-				macro_x[MACRO_HOSTACKCOMMENT]=strdup(ack_data);
+				macro_x[MACRO_HOSTACKCOMMENT]=mt_strdup(ack_data);
 	                }
 
 		/* set the notification type macro */
 		if(macro_x[MACRO_NOTIFICATIONTYPE]!=NULL)
-			free(macro_x[MACRO_NOTIFICATIONTYPE]);
-		macro_x[MACRO_NOTIFICATIONTYPE]=(char *)malloc(MAX_NOTIFICATIONTYPE_LENGTH);
+			mt_free(macro_x[MACRO_NOTIFICATIONTYPE]);
+		macro_x[MACRO_NOTIFICATIONTYPE]=(char *)mt_malloc(MAX_NOTIFICATIONTYPE_LENGTH);
 		if(macro_x[MACRO_NOTIFICATIONTYPE]!=NULL){
 			if(type==NOTIFICATION_ACKNOWLEDGEMENT)
 				strcpy(macro_x[MACRO_NOTIFICATIONTYPE],"ACKNOWLEDGEMENT");
@@ -909,8 +909,8 @@
 
 		/* set the notification number macro */
 		if(macro_x[MACRO_NOTIFICATIONNUMBER]!=NULL)
-			free(macro_x[MACRO_NOTIFICATIONNUMBER]);
-		macro_x[MACRO_NOTIFICATIONNUMBER]=(char *)malloc(MAX_NOTIFICATIONNUMBER_LENGTH);
+			mt_free(macro_x[MACRO_NOTIFICATIONNUMBER]);
+		macro_x[MACRO_NOTIFICATIONNUMBER]=(char *)mt_malloc(MAX_NOTIFICATIONNUMBER_LENGTH);
 		if(macro_x[MACRO_NOTIFICATIONNUMBER]!=NULL){
 			snprintf(macro_x[MACRO_NOTIFICATIONNUMBER],MAX_NOTIFICATIONNUMBER_LENGTH-1,"%d",hst->current_notification_number);
 			macro_x[MACRO_NOTIFICATIONNUMBER][MAX_NOTIFICATIONNUMBER_LENGTH-1]='\x0';
@@ -1682,7 +1682,7 @@
 		return OK;
 
 	/* allocate memory for a new contact in the notification list */
-	new_notification=malloc(sizeof(notification));
+	new_notification=mt_malloc(sizeof(notification));
 	if(new_notification==NULL)
 		return ERROR;
 
diff -urN /home/exon/Nagios/base/utils.c ./base/utils.c
--- /home/exon/Nagios/base/utils.c	2004-12-01 20:16:02.000000000 +0100
+++ ./base/utils.c	2004-12-01 22:46:52.000000000 +0100
@@ -450,7 +450,7 @@
 
 					/* free memory if necessary */
 					if(options & URL_ENCODE_MACRO_CHARS)
-						free(selected_macro);
+						mt_free(selected_macro);
 #ifdef TEST_MACROS
 					printf("    Just finished macro.  Running output: '%s'\n",output_buffer);
 #endif
@@ -494,44 +494,44 @@
 
 	/* get the service description */
 	if(macro_x[MACRO_SERVICEDESC]!=NULL)
-		free(macro_x[MACRO_SERVICEDESC]);
-	macro_x[MACRO_SERVICEDESC]=strdup(svc->description);
+		mt_free(macro_x[MACRO_SERVICEDESC]);
+	macro_x[MACRO_SERVICEDESC]=mt_strdup(svc->description);
 
 	/* get the plugin output */
 	if(macro_x[MACRO_SERVICEOUTPUT]!=NULL)
-		free(macro_x[MACRO_SERVICEOUTPUT]);
+		mt_free(macro_x[MACRO_SERVICEOUTPUT]);
 	if(svc->plugin_output==NULL)
 		macro_x[MACRO_SERVICEOUTPUT]=NULL;
 	else
-		macro_x[MACRO_SERVICEOUTPUT]=strdup(svc->plugin_output);
+		macro_x[MACRO_SERVICEOUTPUT]=mt_strdup(svc->plugin_output);
 
 	/* get the performance data */
 	if(macro_x[MACRO_SERVICEPERFDATA]!=NULL)
-		free(macro_x[MACRO_SERVICEPERFDATA]);
+		mt_free(macro_x[MACRO_SERVICEPERFDATA]);
 	if(svc->perf_data==NULL)
 		macro_x[MACRO_SERVICEPERFDATA]=NULL;
 	else
-		macro_x[MACRO_SERVICEPERFDATA]=strdup(svc->perf_data);
+		macro_x[MACRO_SERVICEPERFDATA]=mt_strdup(svc->perf_data);
 
 	/* get the service check command */
 	if(macro_x[MACRO_SERVICECHECKCOMMAND]!=NULL)
-		free(macro_x[MACRO_SERVICECHECKCOMMAND]);
+		mt_free(macro_x[MACRO_SERVICECHECKCOMMAND]);
 	if(svc->service_check_command==NULL)
 		macro_x[MACRO_SERVICECHECKCOMMAND]=NULL;
 	else
-		macro_x[MACRO_SERVICECHECKCOMMAND]=strdup(svc->service_check_command);
+		macro_x[MACRO_SERVICECHECKCOMMAND]=mt_strdup(svc->service_check_command);
 
 	/* grab the service state type macro (this is usually overridden later on) */
 	if(macro_x[MACRO_SERVICESTATETYPE]!=NULL)
-		free(macro_x[MACRO_SERVICESTATETYPE]);
-	macro_x[MACRO_SERVICESTATETYPE]=(char *)malloc(MAX_STATETYPE_LENGTH);
+		mt_free(macro_x[MACRO_SERVICESTATETYPE]);
+	macro_x[MACRO_SERVICESTATETYPE]=(char *)mt_malloc(MAX_STATETYPE_LENGTH);
 	if(macro_x[MACRO_SERVICESTATETYPE]!=NULL)
 		strcpy(macro_x[MACRO_SERVICESTATETYPE],(svc->state_type==HARD_STATE)?"HARD":"SOFT");
 
 	/* get the service state */
 	if(macro_x[MACRO_SERVICESTATE]!=NULL)
-		free(macro_x[MACRO_SERVICESTATE]);
-	macro_x[MACRO_SERVICESTATE]=(char *)malloc(MAX_STATE_LENGTH);
+		mt_free(macro_x[MACRO_SERVICESTATE]);
+	macro_x[MACRO_SERVICESTATE]=(char *)mt_malloc(MAX_STATE_LENGTH);
 	if(macro_x[MACRO_SERVICESTATE]!=NULL){
 		if(svc->current_state==STATE_OK)
 			strcpy(macro_x[MACRO_SERVICESTATE],"OK");
@@ -545,8 +545,8 @@
 
 	/* get the service state id */
 	if(macro_x[MACRO_SERVICESTATEID]!=NULL)
-		free(macro_x[MACRO_SERVICESTATEID]);
-	macro_x[MACRO_SERVICESTATEID]=(char *)malloc(MAX_STATEID_LENGTH);
+		mt_free(macro_x[MACRO_SERVICESTATEID]);
+	macro_x[MACRO_SERVICESTATEID]=(char *)mt_malloc(MAX_STATEID_LENGTH);
 	if(macro_x[MACRO_SERVICESTATEID]!=NULL){
 		snprintf(macro_x[MACRO_SERVICESTATEID],MAX_STATEID_LENGTH,"%d",svc->current_state);
 		macro_x[MACRO_SERVICESTATEID][MAX_STATEID_LENGTH-1]='\x0';
@@ -554,8 +554,8 @@
 
 	/* get the current service check attempt macro */
 	if(macro_x[MACRO_SERVICEATTEMPT]!=NULL)
-		free(macro_x[MACRO_SERVICEATTEMPT]);
-	macro_x[MACRO_SERVICEATTEMPT]=(char *)malloc(MAX_ATTEMPT_LENGTH);
+		mt_free(macro_x[MACRO_SERVICEATTEMPT]);
+	macro_x[MACRO_SERVICEATTEMPT]=(char *)mt_malloc(MAX_ATTEMPT_LENGTH);
 	if(macro_x[MACRO_SERVICEATTEMPT]!=NULL){
 		snprintf(macro_x[MACRO_SERVICEATTEMPT],MAX_ATTEMPT_LENGTH,"%d",svc->current_attempt);
 		macro_x[MACRO_SERVICEATTEMPT][MAX_ATTEMPT_LENGTH-1]='\x0';
@@ -563,8 +563,8 @@
 
 	/* get the execution time macro */
 	if(macro_x[MACRO_SERVICEEXECUTIONTIME]!=NULL)
-		free(macro_x[MACRO_SERVICEEXECUTIONTIME]);
-	macro_x[MACRO_SERVICEEXECUTIONTIME]=(char *)malloc(MAX_EXECUTIONTIME_LENGTH);
+		mt_free(macro_x[MACRO_SERVICEEXECUTIONTIME]);
+	macro_x[MACRO_SERVICEEXECUTIONTIME]=(char *)mt_malloc(MAX_EXECUTIONTIME_LENGTH);
 	if(macro_x[MACRO_SERVICEEXECUTIONTIME]!=NULL){
 		snprintf(macro_x[MACRO_SERVICEEXECUTIONTIME],MAX_EXECUTIONTIME_LENGTH,"%.3f",svc->execution_time);
 		macro_x[MACRO_SERVICEEXECUTIONTIME][MAX_EXECUTIONTIME_LENGTH-1]='\x0';
@@ -572,8 +572,8 @@
 
 	/* get the latency macro */
 	if(macro_x[MACRO_SERVICELATENCY]!=NULL)
-		free(macro_x[MACRO_SERVICELATENCY]);
-	macro_x[MACRO_SERVICELATENCY]=(char *)malloc(MAX_LATENCY_LENGTH);
+		mt_free(macro_x[MACRO_SERVICELATENCY]);
+	macro_x[MACRO_SERVICELATENCY]=(char *)mt_malloc(MAX_LATENCY_LENGTH);
 	if(macro_x[MACRO_SERVICELATENCY]!=NULL){
 		snprintf(macro_x[MACRO_SERVICELATENCY],MAX_LATENCY_LENGTH,"%.3f",svc->latency);
 		macro_x[MACRO_SERVICELATENCY][MAX_LATENCY_LENGTH-1]='\x0';
@@ -581,8 +581,8 @@
 
 	/* get the last check time macro */
 	if(macro_x[MACRO_LASTSERVICECHECK]!=NULL)
-		free(macro_x[MACRO_LASTSERVICECHECK]);
-	macro_x[MACRO_LASTSERVICECHECK]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTSERVICECHECK]);
+	macro_x[MACRO_LASTSERVICECHECK]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTSERVICECHECK]!=NULL){
 		snprintf(macro_x[MACRO_LASTSERVICECHECK],MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_check);
 		macro_x[MACRO_LASTSERVICECHECK][MAX_DATETIME_LENGTH-1]='\x0';
@@ -590,8 +590,8 @@
 
 	/* get the last state change time macro */
 	if(macro_x[MACRO_LASTSERVICESTATECHANGE]!=NULL)
-		free(macro_x[MACRO_LASTSERVICESTATECHANGE]);
-	macro_x[MACRO_LASTSERVICESTATECHANGE]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTSERVICESTATECHANGE]);
+	macro_x[MACRO_LASTSERVICESTATECHANGE]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTSERVICESTATECHANGE]!=NULL){
 		snprintf(macro_x[MACRO_LASTSERVICESTATECHANGE],MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_state_change);
 		macro_x[MACRO_LASTSERVICESTATECHANGE][MAX_DATETIME_LENGTH-1]='\x0';
@@ -599,8 +599,8 @@
 
 	/* get the last time ok macro */
 	if(macro_x[MACRO_LASTSERVICEOK]!=NULL)
-		free(macro_x[MACRO_LASTSERVICEOK]);
-	macro_x[MACRO_LASTSERVICEOK]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTSERVICEOK]);
+	macro_x[MACRO_LASTSERVICEOK]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTSERVICEOK]!=NULL){
 		snprintf(macro_x[MACRO_LASTSERVICEOK],MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_time_ok);
 		macro_x[MACRO_LASTSERVICEOK][MAX_DATETIME_LENGTH-1]='\x0';
@@ -608,8 +608,8 @@
 
 	/* get the last time warning macro */
 	if(macro_x[MACRO_LASTSERVICEWARNING]!=NULL)
-		free(macro_x[MACRO_LASTSERVICEWARNING]);
-	macro_x[MACRO_LASTSERVICEWARNING]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTSERVICEWARNING]);
+	macro_x[MACRO_LASTSERVICEWARNING]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTSERVICEWARNING]!=NULL){
 		snprintf(macro_x[MACRO_LASTSERVICEWARNING],MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_time_warning);
 		macro_x[MACRO_LASTSERVICEWARNING][MAX_DATETIME_LENGTH-1]='\x0';
@@ -617,8 +617,8 @@
 
 	/* get the last time unknown macro */
 	if(macro_x[MACRO_LASTSERVICEUNKNOWN]!=NULL)
-		free(macro_x[MACRO_LASTSERVICEUNKNOWN]);
-	macro_x[MACRO_LASTSERVICEUNKNOWN]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTSERVICEUNKNOWN]);
+	macro_x[MACRO_LASTSERVICEUNKNOWN]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTSERVICEUNKNOWN]!=NULL){
 		snprintf(macro_x[MACRO_LASTSERVICEUNKNOWN],MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_time_unknown);
 		macro_x[MACRO_LASTSERVICEUNKNOWN][MAX_DATETIME_LENGTH-1]='\x0';
@@ -626,8 +626,8 @@
 
 	/* get the last time critical macro */
 	if(macro_x[MACRO_LASTSERVICECRITICAL]!=NULL)
-		free(macro_x[MACRO_LASTSERVICECRITICAL]);
-	macro_x[MACRO_LASTSERVICECRITICAL]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTSERVICECRITICAL]);
+	macro_x[MACRO_LASTSERVICECRITICAL]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTSERVICECRITICAL]!=NULL){
 		snprintf(macro_x[MACRO_LASTSERVICECRITICAL],MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_time_critical);
 		macro_x[MACRO_LASTSERVICECRITICAL][MAX_DATETIME_LENGTH-1]='\x0';
@@ -635,8 +635,8 @@
 
 	/* get the service downtime depth */
 	if(macro_x[MACRO_SERVICEDOWNTIME]!=NULL)
-		free(macro_x[MACRO_SERVICEDOWNTIME]);
-	macro_x[MACRO_SERVICEDOWNTIME]=(char *)malloc(MAX_DOWNTIME_LENGTH);
+		mt_free(macro_x[MACRO_SERVICEDOWNTIME]);
+	macro_x[MACRO_SERVICEDOWNTIME]=(char *)mt_malloc(MAX_DOWNTIME_LENGTH);
 	if(macro_x[MACRO_SERVICEDOWNTIME]!=NULL){
 		snprintf(macro_x[MACRO_SERVICEDOWNTIME],MAX_DOWNTIME_LENGTH,"%d",svc->scheduled_downtime_depth);
 		macro_x[MACRO_SERVICEDOWNTIME][MAX_DOWNTIME_LENGTH-1]='\x0';
@@ -644,8 +644,8 @@
 
 	/* get the percent state change */
 	if(macro_x[MACRO_SERVICEPERCENTCHANGE]!=NULL)
-		free(macro_x[MACRO_SERVICEPERCENTCHANGE]);
-	macro_x[MACRO_SERVICEPERCENTCHANGE]=(char *)malloc(MAX_PERCENTCHANGE_LENGTH);
+		mt_free(macro_x[MACRO_SERVICEPERCENTCHANGE]);
+	macro_x[MACRO_SERVICEPERCENTCHANGE]=(char *)mt_malloc(MAX_PERCENTCHANGE_LENGTH);
 	if(macro_x[MACRO_SERVICEPERCENTCHANGE]!=NULL){
 		snprintf(macro_x[MACRO_SERVICEPERCENTCHANGE],MAX_PERCENTCHANGE_LENGTH,"%.2f",svc->percent_state_change);
 		macro_x[MACRO_SERVICEPERCENTCHANGE][MAX_PERCENTCHANGE_LENGTH-1]='\x0';
@@ -656,8 +656,8 @@
 
 	/* get the state duration in seconds */
 	if(macro_x[MACRO_SERVICEDURATIONSEC]!=NULL)
-		free(macro_x[MACRO_SERVICEDURATIONSEC]);
-	macro_x[MACRO_SERVICEDURATIONSEC]=(char *)malloc(MAX_DURATION_LENGTH);
+		mt_free(macro_x[MACRO_SERVICEDURATIONSEC]);
+	macro_x[MACRO_SERVICEDURATIONSEC]=(char *)mt_malloc(MAX_DURATION_LENGTH);
 	if(macro_x[MACRO_SERVICEDURATIONSEC]!=NULL){
 		snprintf(macro_x[MACRO_SERVICEDURATIONSEC],MAX_DURATION_LENGTH,"%lu",duration);
 		macro_x[MACRO_SERVICEDURATIONSEC][MAX_DURATION_LENGTH-1]='\x0';
@@ -665,8 +665,8 @@
 
 	/* get the state duration */
 	if(macro_x[MACRO_SERVICEDURATION]!=NULL)
-		free(macro_x[MACRO_SERVICEDURATION]);
-	macro_x[MACRO_SERVICEDURATION]=(char *)malloc(MAX_DURATION_LENGTH);
+		mt_free(macro_x[MACRO_SERVICEDURATION]);
+	macro_x[MACRO_SERVICEDURATION]=(char *)mt_malloc(MAX_DURATION_LENGTH);
 	if(macro_x[MACRO_SERVICEDURATION]!=NULL){
 		days=duration/86400;
 		duration-=(days*86400);
@@ -687,43 +687,43 @@
 
 	/* get the servicegroup name */
 	if(macro_x[MACRO_SERVICEGROUPNAME]!=NULL)
-		free(macro_x[MACRO_SERVICEGROUPNAME]);
+		mt_free(macro_x[MACRO_SERVICEGROUPNAME]);
 	macro_x[MACRO_SERVICEGROUPNAME]=NULL;
 	if(temp_servicegroup!=NULL)
-		macro_x[MACRO_SERVICEGROUPNAME]=strdup(temp_servicegroup->group_name);
+		macro_x[MACRO_SERVICEGROUPNAME]=mt_strdup(temp_servicegroup->group_name);
 	
 	/* get the servicegroup alias */
 	if(macro_x[MACRO_SERVICEGROUPALIAS]!=NULL)
-		free(macro_x[MACRO_SERVICEGROUPALIAS]);
+		mt_free(macro_x[MACRO_SERVICEGROUPALIAS]);
 	macro_x[MACRO_SERVICEGROUPALIAS]=NULL;
 	if(temp_servicegroup!=NULL)
-		macro_x[MACRO_SERVICEGROUPALIAS]=strdup(temp_servicegroup->alias);
+		macro_x[MACRO_SERVICEGROUPALIAS]=mt_strdup(temp_servicegroup->alias);
 
 	if((temp_serviceextinfo=find_serviceextinfo(svc->host_name,svc->description))){
 
 		/* get the action url */
 		if(macro_x[MACRO_SERVICEACTIONURL]!=NULL)
-			free(macro_x[MACRO_SERVICEACTIONURL]);
+			mt_free(macro_x[MACRO_SERVICEACTIONURL]);
 		if(temp_serviceextinfo->action_url==NULL)
 			macro_x[MACRO_SERVICEACTIONURL]=NULL;
 		else
-			macro_x[MACRO_SERVICEACTIONURL]=strdup(temp_serviceextinfo->action_url);
+			macro_x[MACRO_SERVICEACTIONURL]=mt_strdup(temp_serviceextinfo->action_url);
 
 		/* get the notes url */
 		if(macro_x[MACRO_SERVICENOTESURL]!=NULL)
-			free(macro_x[MACRO_SERVICENOTESURL]);
+			mt_free(macro_x[MACRO_SERVICENOTESURL]);
 		if(temp_serviceextinfo->notes_url==NULL)
 			macro_x[MACRO_SERVICENOTESURL]=NULL;
 		else
-			macro_x[MACRO_SERVICENOTESURL]=strdup(temp_serviceextinfo->notes_url);
+			macro_x[MACRO_SERVICENOTESURL]=mt_strdup(temp_serviceextinfo->notes_url);
 
 		/* get the notes */
 		if(macro_x[MACRO_SERVICENOTES]!=NULL)
-			free(macro_x[MACRO_SERVICENOTES]);
+			mt_free(macro_x[MACRO_SERVICENOTES]);
 		if(temp_serviceextinfo->notes==NULL)
 			macro_x[MACRO_SERVICENOTES]=NULL;
 		else
-			macro_x[MACRO_SERVICENOTES]=strdup(temp_serviceextinfo->notes);
+			macro_x[MACRO_SERVICENOTES]=mt_strdup(temp_serviceextinfo->notes);
 	        }
 
 	/* get the date/time macros */
@@ -737,13 +737,13 @@
 	/* notes and action URL macros may themselves contain macros, so process them... */
 	if(macro_x[MACRO_SERVICEACTIONURL]!=NULL){
 		process_macros(macro_x[MACRO_SERVICEACTIONURL],temp_buffer,sizeof(temp_buffer),URL_ENCODE_MACRO_CHARS);
-		free(macro_x[MACRO_SERVICEACTIONURL]);
-		macro_x[MACRO_SERVICEACTIONURL]=strdup(temp_buffer);
+		mt_free(macro_x[MACRO_SERVICEACTIONURL]);
+		macro_x[MACRO_SERVICEACTIONURL]=mt_strdup(temp_buffer);
 	        }
 	if(macro_x[MACRO_SERVICENOTESURL]!=NULL){
 		process_macros(macro_x[MACRO_SERVICENOTESURL],temp_buffer,sizeof(temp_buffer),URL_ENCODE_MACRO_CHARS);
-		free(macro_x[MACRO_SERVICENOTESURL]);
-		macro_x[MACRO_SERVICENOTESURL]=strdup(temp_buffer);
+		mt_free(macro_x[MACRO_SERVICENOTESURL]);
+		macro_x[MACRO_SERVICENOTESURL]=mt_strdup(temp_buffer);
 	        }
 
 #ifdef DEBUG0
@@ -772,23 +772,23 @@
 
 	/* get the host name */
 	if(macro_x[MACRO_HOSTNAME]!=NULL)
-		free(macro_x[MACRO_HOSTNAME]);
-	macro_x[MACRO_HOSTNAME]=strdup(hst->name);
+		mt_free(macro_x[MACRO_HOSTNAME]);
+	macro_x[MACRO_HOSTNAME]=mt_strdup(hst->name);
 	
 	/* get the host alias */
 	if(macro_x[MACRO_HOSTALIAS]!=NULL)
-		free(macro_x[MACRO_HOSTALIAS]);
-	macro_x[MACRO_HOSTALIAS]=strdup(hst->alias);
+		mt_free(macro_x[MACRO_HOSTALIAS]);
+	macro_x[MACRO_HOSTALIAS]=mt_strdup(hst->alias);
 
 	/* get the host address */
 	if(macro_x[MACRO_HOSTADDRESS]!=NULL)
-		free(macro_x[MACRO_HOSTADDRESS]);
-	macro_x[MACRO_HOSTADDRESS]=strdup(hst->address);
+		mt_free(macro_x[MACRO_HOSTADDRESS]);
+	macro_x[MACRO_HOSTADDRESS]=mt_strdup(hst->address);
 
 	/* get the host state */
 	if(macro_x[MACRO_HOSTSTATE]!=NULL)
-		free(macro_x[MACRO_HOSTSTATE]);
-	macro_x[MACRO_HOSTSTATE]=(char *)malloc(MAX_STATE_LENGTH);
+		mt_free(macro_x[MACRO_HOSTSTATE]);
+	macro_x[MACRO_HOSTSTATE]=(char *)mt_malloc(MAX_STATE_LENGTH);
 	if(macro_x[MACRO_HOSTSTATE]!=NULL){
 		if(hst->current_state==HOST_DOWN)
 			strcpy(macro_x[MACRO_HOSTSTATE],"DOWN");
@@ -800,8 +800,8 @@
 
 	/* get the host state id */
 	if(macro_x[MACRO_HOSTSTATEID]!=NULL)
-		free(macro_x[MACRO_HOSTSTATEID]);
-	macro_x[MACRO_HOSTSTATEID]=(char *)malloc(MAX_STATEID_LENGTH);
+		mt_free(macro_x[MACRO_HOSTSTATEID]);
+	macro_x[MACRO_HOSTSTATEID]=(char *)mt_malloc(MAX_STATEID_LENGTH);
 	if(macro_x[MACRO_HOSTSTATEID]!=NULL){
 		snprintf(macro_x[MACRO_HOSTSTATEID],MAX_STATEID_LENGTH,"%d",hst->current_state);
 		macro_x[MACRO_HOSTSTATEID][MAX_STATEID_LENGTH-1]='\x0';
@@ -809,39 +809,39 @@
 
 	/* get the host state type macro */
 	if(macro_x[MACRO_HOSTSTATETYPE]!=NULL)
-		free(macro_x[MACRO_HOSTSTATETYPE]);
-	macro_x[MACRO_HOSTSTATETYPE]=(char *)malloc(MAX_STATETYPE_LENGTH);
+		mt_free(macro_x[MACRO_HOSTSTATETYPE]);
+	macro_x[MACRO_HOSTSTATETYPE]=(char *)mt_malloc(MAX_STATETYPE_LENGTH);
 	if(macro_x[MACRO_HOSTSTATETYPE]!=NULL)
 		strcpy(macro_x[MACRO_HOSTSTATETYPE],(hst->state_type==HARD_STATE)?"HARD":"SOFT");
 
 	/* get the plugin output */
 	if(macro_x[MACRO_HOSTOUTPUT]!=NULL)
-		free(macro_x[MACRO_HOSTOUTPUT]);
+		mt_free(macro_x[MACRO_HOSTOUTPUT]);
 	if(hst->plugin_output==NULL)
 		macro_x[MACRO_HOSTOUTPUT]=NULL;
 	else
-		macro_x[MACRO_HOSTOUTPUT]=strdup(hst->plugin_output);
+		macro_x[MACRO_HOSTOUTPUT]=mt_strdup(hst->plugin_output);
 
 	/* get the performance data */
 	if(macro_x[MACRO_HOSTPERFDATA]!=NULL)
-		free(macro_x[MACRO_HOSTPERFDATA]);
+		mt_free(macro_x[MACRO_HOSTPERFDATA]);
 	if(hst->perf_data==NULL)
 		macro_x[MACRO_HOSTPERFDATA]=NULL;
 	else
-		macro_x[MACRO_HOSTPERFDATA]=strdup(hst->perf_data);
+		macro_x[MACRO_HOSTPERFDATA]=mt_strdup(hst->perf_data);
 
 	/* get the host check command */
 	if(macro_x[MACRO_HOSTCHECKCOMMAND]!=NULL)
-		free(macro_x[MACRO_HOSTCHECKCOMMAND]);
+		mt_free(macro_x[MACRO_HOSTCHECKCOMMAND]);
 	if(hst->host_check_command==NULL)
 		macro_x[MACRO_HOSTCHECKCOMMAND]=NULL;
 	else
-		macro_x[MACRO_HOSTCHECKCOMMAND]=strdup(hst->host_check_command);
+		macro_x[MACRO_HOSTCHECKCOMMAND]=mt_strdup(hst->host_check_command);
 
 	/* get the host current attempt */
 	if(macro_x[MACRO_HOSTATTEMPT]!=NULL)
-		free(macro_x[MACRO_HOSTATTEMPT]);
-	macro_x[MACRO_HOSTATTEMPT]=(char *)malloc(MAX_ATTEMPT_LENGTH);
+		mt_free(macro_x[MACRO_HOSTATTEMPT]);
+	macro_x[MACRO_HOSTATTEMPT]=(char *)mt_malloc(MAX_ATTEMPT_LENGTH);
 	if(macro_x[MACRO_HOSTATTEMPT]!=NULL){
 		snprintf(macro_x[MACRO_HOSTATTEMPT],MAX_ATTEMPT_LENGTH,"%d",hst->current_attempt);
 		macro_x[MACRO_HOSTATTEMPT][MAX_ATTEMPT_LENGTH-1]='\x0';
@@ -849,8 +849,8 @@
 
 	/* get the host downtime depth */
 	if(macro_x[MACRO_HOSTDOWNTIME]!=NULL)
-		free(macro_x[MACRO_HOSTDOWNTIME]);
-	macro_x[MACRO_HOSTDOWNTIME]=(char *)malloc(MAX_DOWNTIME_LENGTH);
+		mt_free(macro_x[MACRO_HOSTDOWNTIME]);
+	macro_x[MACRO_HOSTDOWNTIME]=(char *)mt_malloc(MAX_DOWNTIME_LENGTH);
 	if(macro_x[MACRO_HOSTDOWNTIME]!=NULL){
 		snprintf(macro_x[MACRO_HOSTDOWNTIME],MAX_DOWNTIME_LENGTH,"%d",hst->scheduled_downtime_depth);
 		macro_x[MACRO_HOSTDOWNTIME][MAX_DOWNTIME_LENGTH-1]='\x0';
@@ -858,8 +858,8 @@
 
 	/* get the percent state change */
 	if(macro_x[MACRO_HOSTPERCENTCHANGE]!=NULL)
-		free(macro_x[MACRO_HOSTPERCENTCHANGE]);
-	macro_x[MACRO_HOSTPERCENTCHANGE]=(char *)malloc(MAX_PERCENTCHANGE_LENGTH);
+		mt_free(macro_x[MACRO_HOSTPERCENTCHANGE]);
+	macro_x[MACRO_HOSTPERCENTCHANGE]=(char *)mt_malloc(MAX_PERCENTCHANGE_LENGTH);
 	if(macro_x[MACRO_HOSTPERCENTCHANGE]!=NULL){
 		snprintf(macro_x[MACRO_HOSTPERCENTCHANGE],MAX_PERCENTCHANGE_LENGTH,"%.2f",hst->percent_state_change);
 		macro_x[MACRO_HOSTPERCENTCHANGE][MAX_PERCENTCHANGE_LENGTH-1]='\x0';
@@ -870,8 +870,8 @@
 
 	/* get the state duration in seconds */
 	if(macro_x[MACRO_HOSTDURATIONSEC]!=NULL)
-		free(macro_x[MACRO_HOSTDURATIONSEC]);
-	macro_x[MACRO_HOSTDURATIONSEC]=(char *)malloc(MAX_DURATION_LENGTH);
+		mt_free(macro_x[MACRO_HOSTDURATIONSEC]);
+	macro_x[MACRO_HOSTDURATIONSEC]=(char *)mt_malloc(MAX_DURATION_LENGTH);
 	if(macro_x[MACRO_HOSTDURATIONSEC]!=NULL){
 		snprintf(macro_x[MACRO_HOSTDURATIONSEC],MAX_DURATION_LENGTH,"%lu",duration);
 		macro_x[MACRO_HOSTDURATIONSEC][MAX_DURATION_LENGTH-1]='\x0';
@@ -879,8 +879,8 @@
 
 	/* get the state duration */
 	if(macro_x[MACRO_HOSTDURATION]!=NULL)
-		free(macro_x[MACRO_HOSTDURATION]);
-	macro_x[MACRO_HOSTDURATION]=(char *)malloc(MAX_DURATION_LENGTH);
+		mt_free(macro_x[MACRO_HOSTDURATION]);
+	macro_x[MACRO_HOSTDURATION]=(char *)mt_malloc(MAX_DURATION_LENGTH);
 	if(macro_x[MACRO_HOSTDURATION]!=NULL){
 		days=duration/86400;
 		duration-=(days*86400);
@@ -895,8 +895,8 @@
 
 	/* get the execution time macro */
 	if(macro_x[MACRO_HOSTEXECUTIONTIME]!=NULL)
-		free(macro_x[MACRO_HOSTEXECUTIONTIME]);
-	macro_x[MACRO_HOSTEXECUTIONTIME]=(char *)malloc(MAX_EXECUTIONTIME_LENGTH);
+		mt_free(macro_x[MACRO_HOSTEXECUTIONTIME]);
+	macro_x[MACRO_HOSTEXECUTIONTIME]=(char *)mt_malloc(MAX_EXECUTIONTIME_LENGTH);
 	if(macro_x[MACRO_HOSTEXECUTIONTIME]!=NULL){
 		snprintf(macro_x[MACRO_HOSTEXECUTIONTIME],MAX_EXECUTIONTIME_LENGTH,"%.3f",hst->execution_time);
 		macro_x[MACRO_HOSTEXECUTIONTIME][MAX_EXECUTIONTIME_LENGTH-1]='\x0';
@@ -904,8 +904,8 @@
 
 	/* get the latency macro */
 	if(macro_x[MACRO_HOSTLATENCY]!=NULL)
-		free(macro_x[MACRO_HOSTLATENCY]);
-	macro_x[MACRO_HOSTLATENCY]=(char *)malloc(MAX_LATENCY_LENGTH);
+		mt_free(macro_x[MACRO_HOSTLATENCY]);
+	macro_x[MACRO_HOSTLATENCY]=(char *)mt_malloc(MAX_LATENCY_LENGTH);
 	if(macro_x[MACRO_HOSTLATENCY]!=NULL){
 		snprintf(macro_x[MACRO_HOSTLATENCY],MAX_LATENCY_LENGTH,"%.3f",hst->latency);
 		macro_x[MACRO_HOSTLATENCY][MAX_LATENCY_LENGTH-1]='\x0';
@@ -913,8 +913,8 @@
 
 	/* get the last check time macro */
 	if(macro_x[MACRO_LASTHOSTCHECK]!=NULL)
-		free(macro_x[MACRO_LASTHOSTCHECK]);
-	macro_x[MACRO_LASTHOSTCHECK]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTHOSTCHECK]);
+	macro_x[MACRO_LASTHOSTCHECK]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTHOSTCHECK]!=NULL){
 		snprintf(macro_x[MACRO_LASTHOSTCHECK],MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_state_change);
 		macro_x[MACRO_LASTHOSTCHECK][MAX_DATETIME_LENGTH-1]='\x0';
@@ -922,8 +922,8 @@
 
 	/* get the last state change time macro */
 	if(macro_x[MACRO_LASTHOSTSTATECHANGE]!=NULL)
-		free(macro_x[MACRO_LASTHOSTSTATECHANGE]);
-	macro_x[MACRO_LASTHOSTSTATECHANGE]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTHOSTSTATECHANGE]);
+	macro_x[MACRO_LASTHOSTSTATECHANGE]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTHOSTSTATECHANGE]!=NULL){
 		snprintf(macro_x[MACRO_LASTHOSTSTATECHANGE],MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_state_change);
 		macro_x[MACRO_LASTHOSTSTATECHANGE][MAX_DATETIME_LENGTH-1]='\x0';
@@ -931,8 +931,8 @@
 
 	/* get the last time up macro */
 	if(macro_x[MACRO_LASTHOSTUP]!=NULL)
-		free(macro_x[MACRO_LASTHOSTUP]);
-	macro_x[MACRO_LASTHOSTUP]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTHOSTUP]);
+	macro_x[MACRO_LASTHOSTUP]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTHOSTUP]!=NULL){
 		snprintf(macro_x[MACRO_LASTHOSTUP],MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_time_up);
 		macro_x[MACRO_LASTHOSTUP][MAX_DATETIME_LENGTH-1]='\x0';
@@ -940,8 +940,8 @@
 
 	/* get the last time down macro */
 	if(macro_x[MACRO_LASTHOSTDOWN]!=NULL)
-		free(macro_x[MACRO_LASTHOSTDOWN]);
-	macro_x[MACRO_LASTHOSTDOWN]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTHOSTDOWN]);
+	macro_x[MACRO_LASTHOSTDOWN]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTHOSTDOWN]!=NULL){
 		snprintf(macro_x[MACRO_LASTHOSTDOWN],MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_time_down);
 		macro_x[MACRO_LASTHOSTDOWN][MAX_DATETIME_LENGTH-1]='\x0';
@@ -949,8 +949,8 @@
 
 	/* get the last time unreachable macro */
 	if(macro_x[MACRO_LASTHOSTUNREACHABLE]!=NULL)
-		free(macro_x[MACRO_LASTHOSTUNREACHABLE]);
-	macro_x[MACRO_LASTHOSTUNREACHABLE]=(char *)malloc(MAX_DATETIME_LENGTH);
+		mt_free(macro_x[MACRO_LASTHOSTUNREACHABLE]);
+	macro_x[MACRO_LASTHOSTUNREACHABLE]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LASTHOSTUNREACHABLE]!=NULL){
 		snprintf(macro_x[MACRO_LASTHOSTUNREACHABLE],MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_time_unreachable);
 		macro_x[MACRO_LASTHOSTUNREACHABLE][MAX_DATETIME_LENGTH-1]='\x0';
@@ -964,43 +964,43 @@
 
 	/* get the hostgroup name */
 	if(macro_x[MACRO_HOSTGROUPNAME]!=NULL)
-		free(macro_x[MACRO_HOSTGROUPNAME]);
+		mt_free(macro_x[MACRO_HOSTGROUPNAME]);
 	macro_x[MACRO_HOSTGROUPNAME]=NULL;
 	if(temp_hostgroup!=NULL)
-		macro_x[MACRO_HOSTGROUPNAME]=strdup(temp_hostgroup->group_name);
+		macro_x[MACRO_HOSTGROUPNAME]=mt_strdup(temp_hostgroup->group_name);
 	
 	/* get the hostgroup alias */
 	if(macro_x[MACRO_HOSTGROUPALIAS]!=NULL)
-		free(macro_x[MACRO_HOSTGROUPALIAS]);
+		mt_free(macro_x[MACRO_HOSTGROUPALIAS]);
 	macro_x[MACRO_HOSTGROUPALIAS]=NULL;
 	if(temp_hostgroup!=NULL)
-		macro_x[MACRO_HOSTGROUPALIAS]=strdup(temp_hostgroup->alias);
+		macro_x[MACRO_HOSTGROUPALIAS]=mt_strdup(temp_hostgroup->alias);
 
 	if((temp_hostextinfo=find_hostextinfo(hst->name))){
 
 		/* get the action url */
 		if(macro_x[MACRO_HOSTACTIONURL]!=NULL)
-			free(macro_x[MACRO_HOSTACTIONURL]);
+			mt_free(macro_x[MACRO_HOSTACTIONURL]);
 		if(temp_hostextinfo->action_url==NULL)
 			macro_x[MACRO_HOSTACTIONURL]=NULL;
 		else
-			macro_x[MACRO_HOSTACTIONURL]=strdup(temp_hostextinfo->action_url);
+			macro_x[MACRO_HOSTACTIONURL]=mt_strdup(temp_hostextinfo->action_url);
 
 		/* get the notes url */
 		if(macro_x[MACRO_HOSTNOTESURL]!=NULL)
-			free(macro_x[MACRO_HOSTNOTESURL]);
+			mt_free(macro_x[MACRO_HOSTNOTESURL]);
 		if(temp_hostextinfo->notes_url==NULL)
 			macro_x[MACRO_HOSTNOTESURL]=NULL;
 		else
-			macro_x[MACRO_HOSTNOTESURL]=strdup(temp_hostextinfo->notes_url);
+			macro_x[MACRO_HOSTNOTESURL]=mt_strdup(temp_hostextinfo->notes_url);
 
 		/* get the notes */
 		if(macro_x[MACRO_HOSTNOTES]!=NULL)
-			free(macro_x[MACRO_HOSTNOTES]);
+			mt_free(macro_x[MACRO_HOSTNOTES]);
 		if(temp_hostextinfo->notes==NULL)
 			macro_x[MACRO_HOSTNOTES]=NULL;
 		else
-			macro_x[MACRO_HOSTNOTES]=strdup(temp_hostextinfo->notes);
+			macro_x[MACRO_HOSTNOTES]=mt_strdup(temp_hostextinfo->notes);
 	        }
 
 	/* get the date/time macros */
@@ -1014,13 +1014,13 @@
 	/* notes and action URL macros may themselves contain macros, so process them... */
 	if(macro_x[MACRO_HOSTACTIONURL]!=NULL){
 		process_macros(macro_x[MACRO_HOSTACTIONURL],temp_buffer,sizeof(temp_buffer),URL_ENCODE_MACRO_CHARS);
-		free(macro_x[MACRO_HOSTACTIONURL]);
-		macro_x[MACRO_HOSTACTIONURL]=strdup(temp_buffer);
+		mt_free(macro_x[MACRO_HOSTACTIONURL]);
+		macro_x[MACRO_HOSTACTIONURL]=mt_strdup(temp_buffer);
 	        }
 	if(macro_x[MACRO_HOSTNOTESURL]!=NULL){
 		process_macros(macro_x[MACRO_HOSTNOTESURL],temp_buffer,sizeof(temp_buffer),URL_ENCODE_MACRO_CHARS);
-		free(macro_x[MACRO_HOSTNOTESURL]);
-		macro_x[MACRO_HOSTNOTESURL]=strdup(temp_buffer);
+		mt_free(macro_x[MACRO_HOSTNOTESURL]);
+		macro_x[MACRO_HOSTNOTESURL]=mt_strdup(temp_buffer);
 	        }
 
 #ifdef DEBUG0
@@ -1053,19 +1053,19 @@
 
 	/* clear the on-demand macro */
 	if(macro_ondemand!=NULL){
-		free(macro_ondemand);
+		mt_free(macro_ondemand);
 		macro_ondemand=NULL;
 	        }
 
 	/* get the first argument */
-	macro=strdup(str);
+	macro=mt_strdup(str);
 	if(macro==NULL)
 		return ERROR;
 
 	/* get the host name */
 	ptr=strchr(macro,':');
 	if(ptr==NULL){
-		free(macro);
+		mt_free(macro);
 		return ERROR;
 	        }
 	/* terminate the macro name at the first arg's delimiter */
@@ -1093,7 +1093,7 @@
 		else{
 			temp_hostgroup=find_hostgroup(first_arg);
 			if(temp_hostgroup==NULL){
-				free(macro);
+				mt_free(macro);
 				return ERROR;
 				}
 
@@ -1106,8 +1106,8 @@
 			/* process each host in the hostgroup */
 			temp_hostgroupmember=temp_hostgroup->members;
 			if(temp_hostgroupmember==NULL){
-				macro_ondemand=strdup("");
-				free(macro);
+				macro_ondemand=mt_strdup("");
+				mt_free(macro);
 				return OK;
 				}
 			while(1){
@@ -1136,12 +1136,12 @@
 						break;
 					}
 
-				free(macro_ondemand);
+				mt_free(macro_ondemand);
 				macro_ondemand=NULL;
 				}
 
-			free(macro_ondemand);
-			macro_ondemand=strdup(result_buffer);
+			mt_free(macro_ondemand);
+			macro_ondemand=mt_strdup(result_buffer);
 			}
 	        }
 
@@ -1149,7 +1149,7 @@
 
 		/* second args will either be service description or delimiter */
 		if(second_arg==NULL){
-			free(macro);
+			mt_free(macro);
 			return ERROR;
 	                }
 
@@ -1162,7 +1162,7 @@
 		else{
 			temp_servicegroup=find_servicegroup(first_arg);
 			if(temp_servicegroup==NULL){
-				free(macro);
+				mt_free(macro);
 				return ERROR;
 				}
 
@@ -1175,8 +1175,8 @@
 			/* process each service in the servicegroup */
 			temp_servicegroupmember=temp_servicegroup->members;
 			if(temp_servicegroupmember==NULL){
-				macro_ondemand=strdup("");
-				free(macro);
+				macro_ondemand=mt_strdup("");
+				mt_free(macro);
 				return OK;
 				}
 			while(1){
@@ -1205,19 +1205,19 @@
 						break;
 					}
 
-				free(macro_ondemand);
+				mt_free(macro_ondemand);
 				macro_ondemand=NULL;
 				}
 
-			free(macro_ondemand);
-			macro_ondemand=strdup(result_buffer);
+			mt_free(macro_ondemand);
+			macro_ondemand=mt_strdup(result_buffer);
 			}
 	        }
 
 	else
 		return_val=ERROR;
 
-	free(macro);
+	mt_free(macro);
 
 #ifdef DEBUG0
 	printf("grab_on_demand_macro() end\n");
@@ -1260,15 +1260,15 @@
 
 	/* get the host alias */
 	if(!strcmp(macro,"HOSTALIAS"))
-		macro_ondemand=strdup(hst->alias);
+		macro_ondemand=mt_strdup(hst->alias);
 
 	/* get the host address */
 	else if(!strcmp(macro,"HOSTADDRESS"))
-		macro_ondemand=strdup(hst->address);
+		macro_ondemand=mt_strdup(hst->address);
 
 	/* get the host state */
 	else if(!strcmp(macro,"HOSTSTATE")){
-		macro_ondemand=(char *)malloc(MAX_STATE_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_STATE_LENGTH);
 		if(macro_ondemand!=NULL){
 			if(hst->current_state==HOST_DOWN)
 				strcpy(macro_ondemand,"DOWN");
@@ -1281,7 +1281,7 @@
 
 	/* get the host state id */
 	else if(!strcmp(macro,"HOSTSTATEID")){
-		macro_ondemand=(char *)malloc(MAX_STATEID_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_STATEID_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_STATEID_LENGTH,"%d",hst->current_state);
 			macro_ondemand[MAX_STATEID_LENGTH-1]='\x0';
@@ -1290,7 +1290,7 @@
 
 	/* get the host state type macro */
 	else if(!strcmp(macro,"HOSTSTATETYPE")){
-		macro_ondemand=(char *)malloc(MAX_STATETYPE_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_STATETYPE_LENGTH);
 		if(macro_ondemand!=NULL)
 			strcpy(macro_ondemand,(hst->state_type==HARD_STATE)?"HARD":"SOFT");
 	        }
@@ -1300,7 +1300,7 @@
 		if(hst->plugin_output==NULL)
 			macro_ondemand=NULL;
 		else{
-			macro_ondemand=strdup(hst->plugin_output);
+			macro_ondemand=mt_strdup(hst->plugin_output);
 			strip(macro_ondemand);
 		        }
 	        }
@@ -1310,14 +1310,14 @@
 		if(hst->perf_data==NULL)
 			macro_ondemand=NULL;
 		else{
-			macro_ondemand=strdup(hst->perf_data);
+			macro_ondemand=mt_strdup(hst->perf_data);
 			strip(macro_ondemand);
 		        }
 	        }
 
 	/* get the host current attempt */
 	else if(!strcmp(macro,"HOSTATTEMPT")){
-		macro_ondemand=(char *)malloc(MAX_ATTEMPT_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_ATTEMPT_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_ATTEMPT_LENGTH,"%d",hst->current_attempt);
 			macro_ondemand[MAX_ATTEMPT_LENGTH-1]='\x0';
@@ -1326,7 +1326,7 @@
 
 	/* get the host downtime depth */
 	else if(!strcmp(macro,"HOSTDOWNTIME")){
-		macro_ondemand=(char *)malloc(MAX_DOWNTIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DOWNTIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DOWNTIME_LENGTH,"%d",hst->scheduled_downtime_depth);
 			macro_ondemand[MAX_ATTEMPT_LENGTH-1]='\x0';
@@ -1335,7 +1335,7 @@
 
 	/* get the percent state change */
 	else if(!strcmp(macro,"HOSTPERCENTCHANGE")){
-		macro_ondemand=(char *)malloc(MAX_PERCENTCHANGE_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_PERCENTCHANGE_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_PERCENTCHANGE_LENGTH,"%.2f",hst->percent_state_change);
 			macro_ondemand[MAX_PERCENTCHANGE_LENGTH-1]='\x0';
@@ -1344,7 +1344,7 @@
 
 	/* get the state duration in seconds */
 	else if(!strcmp(macro,"HOSTDURATIONSEC")){
-		macro_ondemand=(char *)malloc(MAX_DURATION_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DURATION_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DURATION_LENGTH,"%lu",duration);
 			macro_ondemand[MAX_DURATION_LENGTH-1]='\x0';
@@ -1353,7 +1353,7 @@
 
 	/* get the state duration */
 	else if(!strcmp(macro,"HOSTDURATION")){
-		macro_ondemand=(char *)malloc(MAX_DURATION_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DURATION_LENGTH);
 		if(macro_ondemand!=NULL){
 			days=duration/86400;
 			duration-=(days*86400);
@@ -1369,7 +1369,7 @@
 
 	/* get the execution time macro */
 	else if(!strcmp(macro,"HOSTEXECUTIONTIME")){
-		macro_ondemand=(char *)malloc(MAX_EXECUTIONTIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_EXECUTIONTIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_EXECUTIONTIME_LENGTH,"%.3f",hst->execution_time);
 			macro_ondemand[MAX_EXECUTIONTIME_LENGTH-1]='\x0';
@@ -1378,7 +1378,7 @@
 
 	/* get the latency macro */
 	else if(!strcmp(macro,"HOSTLATENCY")){
-		macro_ondemand=(char *)malloc(MAX_LATENCY_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_LATENCY_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_LATENCY_LENGTH,"%.3f",hst->latency);
 			macro_ondemand[MAX_LATENCY_LENGTH-1]='\x0';
@@ -1387,7 +1387,7 @@
 
 	/* get the last check time macro */
 	else if(!strcmp(macro,"LASTHOSTCHECK")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_state_change);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1396,7 +1396,7 @@
 
 	/* get the last state change time macro */
 	else if(!strcmp(macro,"LASTHOSTSTATECHANGE")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_state_change);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1405,7 +1405,7 @@
 
 	/* get the last time up macro */
 	else if(!strcmp(macro,"LASTHOSTUP")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_time_up);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1414,7 +1414,7 @@
 
 	/* get the last time down macro */
 	else if(!strcmp(macro,"LASTHOSTDOWN")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_time_down);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1423,7 +1423,7 @@
 
 	/* get the last time unreachable macro */
 	else if(!strcmp(macro,"LASTHOSTUNREACHABLE")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)hst->last_time_unreachable);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1433,13 +1433,13 @@
 	/* get the hostgroup name */
 	else if(!strcmp(macro,"HOSTGROUPNAME")){
 		if(temp_hostgroup!=NULL)
-			macro_ondemand=strdup(temp_hostgroup->group_name);
+			macro_ondemand=mt_strdup(temp_hostgroup->group_name);
 	        }
 	
 	/* get the hostgroup alias */
 	else if(!strcmp(macro,"HOSTGROUPALIAS")){
 		if(temp_hostgroup!=NULL)
-			macro_ondemand=strdup(temp_hostgroup->alias);
+			macro_ondemand=mt_strdup(temp_hostgroup->alias);
 	        }
 
 	/* extended info */
@@ -1452,13 +1452,13 @@
 			if(!strcmp(macro,"HOSTACTIONURL")){
 
 				if(temp_hostextinfo->action_url)
-					macro_ondemand=strdup(temp_hostextinfo->action_url);
+					macro_ondemand=mt_strdup(temp_hostextinfo->action_url);
 
 				/* action URL macros may themselves contain macros, so process them... */
 				if(macro_ondemand!=NULL){
 					process_macros(macro_ondemand,temp_buffer,sizeof(temp_buffer),URL_ENCODE_MACRO_CHARS);
-					free(macro_ondemand);
-					macro_ondemand=strdup(temp_buffer);
+					mt_free(macro_ondemand);
+					macro_ondemand=mt_strdup(temp_buffer);
 				        }
 			        }
 
@@ -1466,20 +1466,20 @@
 			if(!strcmp(macro,"HOSTNOTESURL")){
 
 				if(temp_hostextinfo->notes_url)
-					macro_ondemand=strdup(temp_hostextinfo->notes_url);
+					macro_ondemand=mt_strdup(temp_hostextinfo->notes_url);
 
 				/* action URL macros may themselves contain macros, so process them... */
 				if(macro_ondemand!=NULL){
 					process_macros(macro_ondemand,temp_buffer,sizeof(temp_buffer),URL_ENCODE_MACRO_CHARS);
-					free(macro_ondemand);
-					macro_ondemand=strdup(temp_buffer);
+					mt_free(macro_ondemand);
+					macro_ondemand=mt_strdup(temp_buffer);
 				        }
 			        }
 
 			/* notes */
 			if(!strcmp(macro,"HOSTNOTES")){
 				if(temp_hostextinfo->notes)
-					macro_ondemand=strdup(temp_hostextinfo->notes);
+					macro_ondemand=mt_strdup(temp_hostextinfo->notes);
 			        }
 		        }
 	        }
@@ -1531,7 +1531,7 @@
 		if(svc->plugin_output==NULL)
 			macro_ondemand=NULL;
 		else{
-			macro_ondemand=strdup(svc->plugin_output);
+			macro_ondemand=mt_strdup(svc->plugin_output);
 			strip(macro_ondemand);
 		        }
 	        }
@@ -1541,21 +1541,21 @@
 		if(svc->perf_data==NULL)
 			macro_ondemand=NULL;
 		else{
-			macro_ondemand=strdup(svc->perf_data);
+			macro_ondemand=mt_strdup(svc->perf_data);
 			strip(macro_ondemand);
 		        }
 	        }
 
 	/* grab the service state type macro (this is usually overridden later on) */
 	else if(!strcmp(macro,"SERVICESTATETYPE")){
-		macro_ondemand=(char *)malloc(MAX_STATETYPE_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_STATETYPE_LENGTH);
 		if(macro_ondemand!=NULL)
 			strcpy(macro_ondemand,(svc->state_type==HARD_STATE)?"HARD":"SOFT");
 	        }
 
 	/* get the service state */
 	else if(!strcmp(macro,"SERVICESTATE")){
-		macro_ondemand=(char *)malloc(MAX_STATE_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_STATE_LENGTH);
 		if(macro_ondemand!=NULL){
 			if(svc->current_state==STATE_OK)
 				strcpy(macro_ondemand,"OK");
@@ -1570,7 +1570,7 @@
 
 	/* get the service state id */
 	else if(!strcmp(macro,"SERVICESTATEID")){
-		macro_ondemand=(char *)malloc(MAX_STATEID_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_STATEID_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_STATEID_LENGTH,"%d",svc->current_state);
 			macro_ondemand[MAX_STATEID_LENGTH-1]='\x0';
@@ -1579,7 +1579,7 @@
 
 	/* get the current service check attempt macro */
 	else if(!strcmp(macro,"SERVICEATTEMPT")){
-		macro_ondemand=(char *)malloc(MAX_ATTEMPT_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_ATTEMPT_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_ATTEMPT_LENGTH,"%d",svc->current_attempt);
 			macro_ondemand[MAX_ATTEMPT_LENGTH-1]='\x0';
@@ -1588,7 +1588,7 @@
 
 	/* get the execution time macro */
 	else if(!strcmp(macro,"SERVICEEXECUTIONTIME")){
-		macro_ondemand=(char *)malloc(MAX_EXECUTIONTIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_EXECUTIONTIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_EXECUTIONTIME_LENGTH,"%.3f",svc->execution_time);
 			macro_ondemand[MAX_EXECUTIONTIME_LENGTH-1]='\x0';
@@ -1597,7 +1597,7 @@
 
 	/* get the latency macro */
 	else if(!strcmp(macro,"SERVICELATENCY")){
-		macro_ondemand=(char *)malloc(MAX_LATENCY_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_LATENCY_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_LATENCY_LENGTH,"%.3f",svc->latency);
 			macro_ondemand[MAX_LATENCY_LENGTH-1]='\x0';
@@ -1606,7 +1606,7 @@
 
 	/* get the last check time macro */
 	else if(!strcmp(macro,"LASTSERVICECHECK")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_check);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1615,7 +1615,7 @@
 
 	/* get the last state change time macro */
 	else if(!strcmp(macro,"LASTSERVICESTATECHANGE")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_state_change);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1624,7 +1624,7 @@
 
 	/* get the last time ok macro */
 	else if(!strcmp(macro,"LASTSERVICEOK")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_time_ok);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1633,7 +1633,7 @@
 
 	/* get the last time warning macro */
 	else if(!strcmp(macro,"LASTSERVICEWARNING")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_time_warning);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1642,7 +1642,7 @@
 
 	/* get the last time unknown macro */
 	else if(!strcmp(macro,"LASTSERVICEUNKNOWN")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_time_unknown);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1651,7 +1651,7 @@
 
 	/* get the last time critical macro */
 	else if(!strcmp(macro,"LASTSERVICECRITICAL")){
-		macro_ondemand=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DATETIME_LENGTH,"%lu",(unsigned long)svc->last_time_critical);
 			macro_ondemand[MAX_DATETIME_LENGTH-1]='\x0';
@@ -1660,7 +1660,7 @@
 
 	/* get the service downtime depth */
 	else if(!strcmp(macro,"SERVICEDOWNTIME")){
-		macro_ondemand=(char *)malloc(MAX_DOWNTIME_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DOWNTIME_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DOWNTIME_LENGTH,"%d",svc->scheduled_downtime_depth);
 			macro_ondemand[MAX_DOWNTIME_LENGTH-1]='\x0';
@@ -1669,7 +1669,7 @@
 
 	/* get the percent state change */
 	else if(!strcmp(macro,"SERVICEPERCENTCHANGE")){
-		macro_ondemand=(char *)malloc(MAX_PERCENTCHANGE_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_PERCENTCHANGE_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_PERCENTCHANGE_LENGTH,"%.2f",svc->percent_state_change);
 			macro_ondemand[MAX_PERCENTCHANGE_LENGTH-1]='\x0';
@@ -1678,7 +1678,7 @@
 
 	/* get the state duration in seconds */
 	else if(!strcmp(macro,"SERVICEDURATIONSEC")){
-		macro_ondemand=(char *)malloc(MAX_DURATION_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DURATION_LENGTH);
 		if(macro_ondemand!=NULL){
 			snprintf(macro_ondemand,MAX_DURATION_LENGTH,"%lu",duration);
 			macro_ondemand[MAX_DURATION_LENGTH-1]='\x0';
@@ -1687,7 +1687,7 @@
 
 	/* get the state duration */
 	else if(!strcmp(macro,"SERVICEDURATION")){
-		macro_ondemand=(char *)malloc(MAX_DURATION_LENGTH);
+		macro_ondemand=(char *)mt_malloc(MAX_DURATION_LENGTH);
 		if(macro_ondemand!=NULL){
 			days=duration/86400;
 			duration-=(days*86400);
@@ -1704,13 +1704,13 @@
 	/* get the servicegroup name */
 	else if(!strcmp(macro,"SERVICEGROUPNAME")){
 		if(temp_servicegroup!=NULL)
-			macro_ondemand=strdup(temp_servicegroup->group_name);
+			macro_ondemand=mt_strdup(temp_servicegroup->group_name);
 	        }
 	
 	/* get the servicegroup alias */
 	else if(!strcmp(macro,"SERVICEGROUPALIAS")){
 		if(temp_servicegroup!=NULL)
-			macro_ondemand=strdup(temp_servicegroup->alias);
+			macro_ondemand=mt_strdup(temp_servicegroup->alias);
 	        }
 
 	/* extended info */
@@ -1723,13 +1723,13 @@
 			if(!strcmp(macro,"SERVICEACTIONURL")){
 
 				if(temp_serviceextinfo->action_url)
-					macro_ondemand=strdup(temp_serviceextinfo->action_url);
+					macro_ondemand=mt_strdup(temp_serviceextinfo->action_url);
 
 				/* action URL macros may themselves contain macros, so process them... */
 				if(macro_ondemand!=NULL){
 					process_macros(macro_ondemand,temp_buffer,sizeof(temp_buffer),URL_ENCODE_MACRO_CHARS);
-					free(macro_ondemand);
-					macro_ondemand=strdup(temp_buffer);
+					mt_free(macro_ondemand);
+					macro_ondemand=mt_strdup(temp_buffer);
 				        }
 			        }
 
@@ -1737,20 +1737,20 @@
 			if(!strcmp(macro,"SERVICENOTESURL")){
 
 				if(temp_serviceextinfo->notes_url)
-					macro_ondemand=strdup(temp_serviceextinfo->notes_url);
+					macro_ondemand=mt_strdup(temp_serviceextinfo->notes_url);
 
 				/* action URL macros may themselves contain macros, so process them... */
 				if(macro_ondemand!=NULL){
 					process_macros(macro_ondemand,temp_buffer,sizeof(temp_buffer),URL_ENCODE_MACRO_CHARS);
-					free(macro_ondemand);
-					macro_ondemand=strdup(temp_buffer);
+					mt_free(macro_ondemand);
+					macro_ondemand=mt_strdup(temp_buffer);
 				        }
 			        }
 
 			/* notes */
 			if(!strcmp(macro,"SERVICENOTES")){
 				if(temp_serviceextinfo->notes)
-					macro_ondemand=strdup(temp_serviceextinfo->notes);
+					macro_ondemand=mt_strdup(temp_serviceextinfo->notes);
 			        }
 		        }
 	        }
@@ -1776,38 +1776,38 @@
 
 	/* get the name */
 	if(macro_x[MACRO_CONTACTNAME]!=NULL)
-		free(macro_x[MACRO_CONTACTNAME]);
-	macro_x[MACRO_CONTACTNAME]=strdup(cntct->name);
+		mt_free(macro_x[MACRO_CONTACTNAME]);
+	macro_x[MACRO_CONTACTNAME]=mt_strdup(cntct->name);
 
 	/* get the alias */
 	if(macro_x[MACRO_CONTACTALIAS]!=NULL)
-		free(macro_x[MACRO_CONTACTALIAS]);
-	macro_x[MACRO_CONTACTALIAS]=strdup(cntct->alias);
+		mt_free(macro_x[MACRO_CONTACTALIAS]);
+	macro_x[MACRO_CONTACTALIAS]=mt_strdup(cntct->alias);
 
 	/* get the email address */
 	if(macro_x[MACRO_CONTACTEMAIL]!=NULL)
-		free(macro_x[MACRO_CONTACTEMAIL]);
+		mt_free(macro_x[MACRO_CONTACTEMAIL]);
 	if(cntct->email==NULL)
 		macro_x[MACRO_CONTACTEMAIL]=NULL;
 	else
-		macro_x[MACRO_CONTACTEMAIL]=strdup(cntct->email);
+		macro_x[MACRO_CONTACTEMAIL]=mt_strdup(cntct->email);
 
 	/* get the pager number */
 	if(macro_x[MACRO_CONTACTPAGER]!=NULL)
-		free(macro_x[MACRO_CONTACTPAGER]);
+		mt_free(macro_x[MACRO_CONTACTPAGER]);
 	if(cntct->pager==NULL)
 		macro_x[MACRO_CONTACTPAGER]=NULL;
 	else
-		macro_x[MACRO_CONTACTPAGER]=strdup(cntct->pager);
+		macro_x[MACRO_CONTACTPAGER]=mt_strdup(cntct->pager);
 
 	/* get misc contact addresses */
 	for(x=0;x<MAX_CONTACT_ADDRESSES;x++){
 		if(macro_contactaddress[x]!=NULL)
-			free(macro_contactaddress[x]);
+			mt_free(macro_contactaddress[x]);
 		if(cntct->address[x]==NULL)
 			macro_contactaddress[x]=NULL;
 		else
-			macro_contactaddress[x]=strdup(cntct->address[x]);
+			macro_contactaddress[x]=mt_strdup(cntct->address[x]);
 	        }
 
 	/* get the date/time macros */
@@ -1963,8 +1963,8 @@
 
 	/* get total hosts up */
 	if(macro_x[MACRO_TOTALHOSTSUP]!=NULL)
-		free(macro_x[MACRO_TOTALHOSTSUP]);
-	macro_x[MACRO_TOTALHOSTSUP]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALHOSTSUP]);
+	macro_x[MACRO_TOTALHOSTSUP]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALHOSTSUP]!=NULL){
 		snprintf(macro_x[MACRO_TOTALHOSTSUP],MAX_TOTALS_LENGTH,"%d",hosts_up);
 		macro_x[MACRO_TOTALHOSTSUP][MAX_TOTALS_LENGTH-1]='\x0';
@@ -1972,8 +1972,8 @@
 
 	/* get total hosts down */
 	if(macro_x[MACRO_TOTALHOSTSDOWN]!=NULL)
-		free(macro_x[MACRO_TOTALHOSTSDOWN]);
-	macro_x[MACRO_TOTALHOSTSDOWN]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALHOSTSDOWN]);
+	macro_x[MACRO_TOTALHOSTSDOWN]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALHOSTSDOWN]!=NULL){
 		snprintf(macro_x[MACRO_TOTALHOSTSDOWN],MAX_TOTALS_LENGTH,"%d",hosts_down);
 		macro_x[MACRO_TOTALHOSTSDOWN][MAX_TOTALS_LENGTH-1]='\x0';
@@ -1981,8 +1981,8 @@
 
 	/* get total hosts unreachable */
 	if(macro_x[MACRO_TOTALHOSTSUNREACHABLE]!=NULL)
-		free(macro_x[MACRO_TOTALHOSTSUNREACHABLE]);
-	macro_x[MACRO_TOTALHOSTSUNREACHABLE]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALHOSTSUNREACHABLE]);
+	macro_x[MACRO_TOTALHOSTSUNREACHABLE]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALHOSTSUNREACHABLE]!=NULL){
 		snprintf(macro_x[MACRO_TOTALHOSTSUNREACHABLE],MAX_TOTALS_LENGTH,"%d",hosts_unreachable);
 		macro_x[MACRO_TOTALHOSTSUNREACHABLE][MAX_TOTALS_LENGTH-1]='\x0';
@@ -1990,8 +1990,8 @@
 
 	/* get total unhandled hosts down */
 	if(macro_x[MACRO_TOTALHOSTSDOWNUNHANDLED]!=NULL)
-		free(macro_x[MACRO_TOTALHOSTSDOWNUNHANDLED]);
-	macro_x[MACRO_TOTALHOSTSDOWNUNHANDLED]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALHOSTSDOWNUNHANDLED]);
+	macro_x[MACRO_TOTALHOSTSDOWNUNHANDLED]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALHOSTSDOWNUNHANDLED]!=NULL){
 		snprintf(macro_x[MACRO_TOTALHOSTSDOWNUNHANDLED],MAX_TOTALS_LENGTH,"%d",hosts_down_unhandled);
 		macro_x[MACRO_TOTALHOSTSDOWNUNHANDLED][MAX_TOTALS_LENGTH-1]='\x0';
@@ -1999,8 +1999,8 @@
 
 	/* get total unhandled hosts unreachable */
 	if(macro_x[MACRO_TOTALHOSTSUNREACHABLEUNHANDLED]!=NULL)
-		free(macro_x[MACRO_TOTALHOSTSUNREACHABLEUNHANDLED]);
-	macro_x[MACRO_TOTALHOSTSUNREACHABLEUNHANDLED]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALHOSTSUNREACHABLEUNHANDLED]);
+	macro_x[MACRO_TOTALHOSTSUNREACHABLEUNHANDLED]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALHOSTSUNREACHABLEUNHANDLED]!=NULL){
 		snprintf(macro_x[MACRO_TOTALHOSTSUNREACHABLEUNHANDLED],MAX_TOTALS_LENGTH,"%d",hosts_unreachable_unhandled);
 		macro_x[MACRO_TOTALHOSTSUNREACHABLEUNHANDLED][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2008,8 +2008,8 @@
 
 	/* get total host problems */
 	if(macro_x[MACRO_TOTALHOSTPROBLEMS]!=NULL)
-		free(macro_x[MACRO_TOTALHOSTPROBLEMS]);
-	macro_x[MACRO_TOTALHOSTPROBLEMS]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALHOSTPROBLEMS]);
+	macro_x[MACRO_TOTALHOSTPROBLEMS]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALHOSTPROBLEMS]!=NULL){
 		snprintf(macro_x[MACRO_TOTALHOSTPROBLEMS],MAX_TOTALS_LENGTH,"%d",host_problems);
 		macro_x[MACRO_TOTALHOSTPROBLEMS][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2017,8 +2017,8 @@
 
 	/* get total unhandled host problems */
 	if(macro_x[MACRO_TOTALHOSTPROBLEMSUNHANDLED]!=NULL)
-		free(macro_x[MACRO_TOTALHOSTPROBLEMSUNHANDLED]);
-	macro_x[MACRO_TOTALHOSTPROBLEMSUNHANDLED]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALHOSTPROBLEMSUNHANDLED]);
+	macro_x[MACRO_TOTALHOSTPROBLEMSUNHANDLED]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALHOSTPROBLEMSUNHANDLED]!=NULL){
 		snprintf(macro_x[MACRO_TOTALHOSTPROBLEMSUNHANDLED],MAX_TOTALS_LENGTH,"%d",host_problems_unhandled);
 		macro_x[MACRO_TOTALHOSTPROBLEMSUNHANDLED][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2026,8 +2026,8 @@
 
 	/* get total services ok */
 	if(macro_x[MACRO_TOTALSERVICESOK]!=NULL)
-		free(macro_x[MACRO_TOTALSERVICESOK]);
-	macro_x[MACRO_TOTALSERVICESOK]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALSERVICESOK]);
+	macro_x[MACRO_TOTALSERVICESOK]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALSERVICESOK]!=NULL){
 		snprintf(macro_x[MACRO_TOTALSERVICESOK],MAX_TOTALS_LENGTH,"%d",services_ok);
 		macro_x[MACRO_TOTALSERVICESOK][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2035,8 +2035,8 @@
 
 	/* get total services warning */
 	if(macro_x[MACRO_TOTALSERVICESWARNING]!=NULL)
-		free(macro_x[MACRO_TOTALSERVICESWARNING]);
-	macro_x[MACRO_TOTALSERVICESWARNING]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALSERVICESWARNING]);
+	macro_x[MACRO_TOTALSERVICESWARNING]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALSERVICESWARNING]!=NULL){
 		snprintf(macro_x[MACRO_TOTALSERVICESWARNING],MAX_TOTALS_LENGTH,"%d",services_warning);
 		macro_x[MACRO_TOTALSERVICESWARNING][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2044,8 +2044,8 @@
 
 	/* get total services critical */
 	if(macro_x[MACRO_TOTALSERVICESCRITICAL]!=NULL)
-		free(macro_x[MACRO_TOTALSERVICESCRITICAL]);
-	macro_x[MACRO_TOTALSERVICESCRITICAL]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALSERVICESCRITICAL]);
+	macro_x[MACRO_TOTALSERVICESCRITICAL]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALSERVICESCRITICAL]!=NULL){
 		snprintf(macro_x[MACRO_TOTALSERVICESCRITICAL],MAX_TOTALS_LENGTH,"%d",services_critical);
 		macro_x[MACRO_TOTALSERVICESCRITICAL][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2053,8 +2053,8 @@
 
 	/* get total services unknown */
 	if(macro_x[MACRO_TOTALSERVICESUNKNOWN]!=NULL)
-		free(macro_x[MACRO_TOTALSERVICESUNKNOWN]);
-	macro_x[MACRO_TOTALSERVICESUNKNOWN]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALSERVICESUNKNOWN]);
+	macro_x[MACRO_TOTALSERVICESUNKNOWN]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALSERVICESUNKNOWN]!=NULL){
 		snprintf(macro_x[MACRO_TOTALSERVICESUNKNOWN],MAX_TOTALS_LENGTH,"%d",services_unknown);
 		macro_x[MACRO_TOTALSERVICESUNKNOWN][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2062,8 +2062,8 @@
 
 	/* get total unhandled services warning */
 	if(macro_x[MACRO_TOTALSERVICESWARNINGUNHANDLED]!=NULL)
-		free(macro_x[MACRO_TOTALSERVICESWARNINGUNHANDLED]);
-	macro_x[MACRO_TOTALSERVICESWARNINGUNHANDLED]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALSERVICESWARNINGUNHANDLED]);
+	macro_x[MACRO_TOTALSERVICESWARNINGUNHANDLED]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALSERVICESWARNINGUNHANDLED]!=NULL){
 		snprintf(macro_x[MACRO_TOTALSERVICESWARNINGUNHANDLED],MAX_TOTALS_LENGTH,"%d",services_warning_unhandled);
 		macro_x[MACRO_TOTALSERVICESWARNINGUNHANDLED][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2071,8 +2071,8 @@
 
 	/* get total unhandled services critical */
 	if(macro_x[MACRO_TOTALSERVICESCRITICALUNHANDLED]!=NULL)
-		free(macro_x[MACRO_TOTALSERVICESCRITICALUNHANDLED]);
-	macro_x[MACRO_TOTALSERVICESCRITICALUNHANDLED]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALSERVICESCRITICALUNHANDLED]);
+	macro_x[MACRO_TOTALSERVICESCRITICALUNHANDLED]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALSERVICESCRITICALUNHANDLED]!=NULL){
 		snprintf(macro_x[MACRO_TOTALSERVICESCRITICALUNHANDLED],MAX_TOTALS_LENGTH,"%d",services_critical_unhandled);
 		macro_x[MACRO_TOTALSERVICESCRITICALUNHANDLED][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2080,8 +2080,8 @@
 
 	/* get total unhandled services unknown */
 	if(macro_x[MACRO_TOTALSERVICESUNKNOWNUNHANDLED]!=NULL)
-		free(macro_x[MACRO_TOTALSERVICESUNKNOWNUNHANDLED]);
-	macro_x[MACRO_TOTALSERVICESUNKNOWNUNHANDLED]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALSERVICESUNKNOWNUNHANDLED]);
+	macro_x[MACRO_TOTALSERVICESUNKNOWNUNHANDLED]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALSERVICESUNKNOWNUNHANDLED]!=NULL){
 		snprintf(macro_x[MACRO_TOTALSERVICESUNKNOWNUNHANDLED],MAX_TOTALS_LENGTH,"%d",services_unknown_unhandled);
 		macro_x[MACRO_TOTALSERVICESUNKNOWNUNHANDLED][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2089,8 +2089,8 @@
 
 	/* get total service problems */
 	if(macro_x[MACRO_TOTALSERVICEPROBLEMS]!=NULL)
-		free(macro_x[MACRO_TOTALSERVICEPROBLEMS]);
-	macro_x[MACRO_TOTALSERVICEPROBLEMS]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALSERVICEPROBLEMS]);
+	macro_x[MACRO_TOTALSERVICEPROBLEMS]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALSERVICEPROBLEMS]!=NULL){
 		snprintf(macro_x[MACRO_TOTALSERVICEPROBLEMS],MAX_TOTALS_LENGTH,"%d",service_problems);
 		macro_x[MACRO_TOTALSERVICEPROBLEMS][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2098,8 +2098,8 @@
 
 	/* get total unhandled service problems */
 	if(macro_x[MACRO_TOTALSERVICEPROBLEMSUNHANDLED]!=NULL)
-		free(macro_x[MACRO_TOTALSERVICEPROBLEMSUNHANDLED]);
-	macro_x[MACRO_TOTALSERVICEPROBLEMSUNHANDLED]=(char *)malloc(MAX_TOTALS_LENGTH);
+		mt_free(macro_x[MACRO_TOTALSERVICEPROBLEMSUNHANDLED]);
+	macro_x[MACRO_TOTALSERVICEPROBLEMSUNHANDLED]=(char *)mt_malloc(MAX_TOTALS_LENGTH);
 	if(macro_x[MACRO_TOTALSERVICEPROBLEMSUNHANDLED]!=NULL){
 		snprintf(macro_x[MACRO_TOTALSERVICEPROBLEMSUNHANDLED],MAX_TOTALS_LENGTH,"%d",service_problems_unhandled);
 		macro_x[MACRO_TOTALSERVICEPROBLEMSUNHANDLED][MAX_TOTALS_LENGTH-1]='\x0';
@@ -2127,31 +2127,31 @@
 
 	/* get the current date/time (long format macro) */
 	if(macro_x[MACRO_LONGDATETIME]==NULL)
-		macro_x[MACRO_LONGDATETIME]=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_x[MACRO_LONGDATETIME]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_LONGDATETIME]!=NULL)
 		get_datetime_string(&t,macro_x[MACRO_LONGDATETIME],MAX_DATETIME_LENGTH,LONG_DATE_TIME);
 
 	/* get the current date/time (short format macro) */
 	if(macro_x[MACRO_SHORTDATETIME]==NULL)
-		macro_x[MACRO_SHORTDATETIME]=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_x[MACRO_SHORTDATETIME]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_SHORTDATETIME]!=NULL)
 		get_datetime_string(&t,macro_x[MACRO_SHORTDATETIME],MAX_DATETIME_LENGTH,SHORT_DATE_TIME);
 
 	/* get the short format date macro */
 	if(macro_x[MACRO_DATE]==NULL)
-		macro_x[MACRO_DATE]=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_x[MACRO_DATE]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_DATE]!=NULL)
 		get_datetime_string(&t,macro_x[MACRO_DATE],MAX_DATETIME_LENGTH,SHORT_DATE);
 
 	/* get the short format time macro */
 	if(macro_x[MACRO_TIME]==NULL)
-		macro_x[MACRO_TIME]=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_x[MACRO_TIME]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_TIME]!=NULL)
 		get_datetime_string(&t,macro_x[MACRO_TIME],MAX_DATETIME_LENGTH,SHORT_TIME);
 
 	/* get the time_t format time macro */
 	if(macro_x[MACRO_TIMET]==NULL)
-		macro_x[MACRO_TIMET]=(char *)malloc(MAX_DATETIME_LENGTH);
+		macro_x[MACRO_TIMET]=(char *)mt_malloc(MAX_DATETIME_LENGTH);
 	if(macro_x[MACRO_TIMET]!=NULL){
 		snprintf(macro_x[MACRO_TIMET],MAX_DATETIME_LENGTH,"%lu",(unsigned long)t);
 		macro_x[MACRO_TIMET][MAX_DATETIME_LENGTH-1]='\x0';
@@ -2184,7 +2184,7 @@
 	/* command argument macros */
 	for(x=0;x<MAX_COMMAND_ARGUMENTS;x++){
 		if(macro_argv[x]!=NULL){
-			free(macro_argv[x]);
+			mt_free(macro_argv[x]);
 			macro_argv[x]=NULL;
 		        }
 	        }
@@ -2225,7 +2225,7 @@
 			break;
 		default:
 			if(macro_x[x]!=NULL){
-				free(macro_x[x]);
+				mt_free(macro_x[x]);
 				macro_x[x]=NULL;
 			        }
 			break;
@@ -2235,7 +2235,7 @@
 	/* command argument macros */
 	for(x=0;x<MAX_COMMAND_ARGUMENTS;x++){
 		if(macro_argv[x]!=NULL){
-			free(macro_argv[x]);
+			mt_free(macro_argv[x]);
 			macro_argv[x]=NULL;
 		        }
 	        }
@@ -2243,14 +2243,14 @@
 	/* contact address macros */
 	for(x=0;x<MAX_CONTACT_ADDRESSES;x++){
 		if(macro_contactaddress[x]!=NULL){
-			free(macro_contactaddress[x]);
+			mt_free(macro_contactaddress[x]);
 			macro_contactaddress[x]=NULL;
 		        }
 	        }
 
 	/* clear on-demand macro */
 	if(macro_ondemand!=NULL){
-		free(macro_ondemand);
+		mt_free(macro_ondemand);
 		macro_ondemand=NULL;
 	        }
 
@@ -2289,7 +2289,7 @@
 		case MACRO_HOSTPERFDATAFILE:
 		case MACRO_SERVICEPERFDATAFILE:
 			if(macro_x[x]!=NULL){
-				free(macro_x[x]);
+				mt_free(macro_x[x]);
 				macro_x[x]=NULL;
 			        }
 			break;
@@ -2428,7 +2428,7 @@
 int add_macrox_name(int index, char *name){
 
 	/* dup the macro name */
-	macro_x_names[index]=strdup(name);
+	macro_x_names[index]=mt_strdup(name);
 
 	return OK;
         }
@@ -2444,7 +2444,7 @@
 
 	/* free each macro name */
 	for(x=0;x<MACRO_X_COUNT;x++){
-		free(macro_x_names[x]);
+		mt_free(macro_x_names[x]);
 		macro_x_names[x]=NULL;
 	        }
 
@@ -2536,7 +2536,7 @@
 		return ERROR;
 
 	/* allocate memory */
-	if((env_macro_name=(char *)malloc(strlen(MACRO_ENV_VAR_PREFIX)+strlen(name)+1))==NULL)
+	if((env_macro_name=(char *)mt_malloc(strlen(MACRO_ENV_VAR_PREFIX)+strlen(name)+1))==NULL)
 		return ERROR;
 
 	/* create the name */
@@ -2551,7 +2551,7 @@
 		unsetenv(env_macro_name);
 
 	/* free allocated memory */
-	free(env_macro_name);
+	mt_free(env_macro_name);
 
 #ifdef DEBUG0
 	printf("set_macro_environment_var() end\n");
@@ -2924,7 +2924,7 @@
 	/* clear the old command arguments */
 	for(x=0;x<MAX_COMMAND_ARGUMENTS;x++){
 		if(macro_argv[x]!=NULL)
-			free(macro_argv[x]);
+			mt_free(macro_argv[x]);
 		macro_argv[x]=NULL;
 	        }
 
@@ -2978,7 +2978,7 @@
 		process_macros(temp_arg,arg_buffer,sizeof(arg_buffer),macro_options);
 
 		strip(arg_buffer);
-		macro_argv[x]=strdup(arg_buffer);
+		macro_argv[x]=mt_strdup(arg_buffer);
 	        }
 
 #ifdef DEBUG1
@@ -3741,7 +3741,7 @@
 		memcpy(message,((service_message **)service_result_buffer.buffer)[service_result_buffer.tail],sizeof(service_message));
 
 		/* free memory allocated for buffer slot */
-		free(((service_message **)service_result_buffer.buffer)[service_result_buffer.tail]);
+		mt_free(((service_message **)service_result_buffer.buffer)[service_result_buffer.tail]);
 		service_result_buffer.buffer[service_result_buffer.tail]=NULL;
 
 		/* adjust tail counter and number of items */
@@ -4070,8 +4070,8 @@
 
 	if(buffer!=NULL){
 		if(original_my_strtok_buffer!=NULL)
-			free(original_my_strtok_buffer);
-		my_strtok_buffer=(char *)malloc(strlen(buffer)+1);
+			mt_free(original_my_strtok_buffer);
+		my_strtok_buffer=(char *)mt_malloc(strlen(buffer)+1);
 		if(my_strtok_buffer==NULL)
 			return NULL;
 		original_my_strtok_buffer=my_strtok_buffer;
@@ -4153,7 +4153,7 @@
 		return NULL;
 
 	/* allocate enough memory to escape all characters if necessary */
-	if((encoded_url_string=(char *)malloc((strlen(input)*3)+1))==NULL)
+	if((encoded_url_string=(char *)mt_malloc((strlen(input)*3)+1))==NULL)
 		return NULL;
 
 	/* check/encode all characters */
@@ -4318,7 +4318,7 @@
 	int mode=O_RDONLY;
 
 	/* allocate memory */
-	if((new_mmapfile=(mmapfile *)malloc(sizeof(mmapfile)))==NULL)
+	if((new_mmapfile=(mmapfile *)mt_malloc(sizeof(mmapfile)))==NULL)
 		return NULL;
 
 	/* open the file */
@@ -4328,19 +4328,19 @@
 	/* get file info */
 	if((fstat(fd,&statbuf))==-1){
 		close(fd);
-		free(new_mmapfile);
+		mt_free(new_mmapfile);
 		return NULL;
 	        }
 
 	/* mmap() the file */
 	if((mmap_buf=(void *)mmap(0,statbuf.st_size,PROT_READ,MAP_PRIVATE,fd,0))==MAP_FAILED){
 		close(fd);
-		free(new_mmapfile);
+		mt_free(new_mmapfile);
 		return NULL;
 	        }
 
 	/* populate struct info for later use */
-	/*new_mmapfile->path=strdup(filename);*/
+	/*new_mmapfile->path=mt_strdup(filename);*/
 	new_mmapfile->path=NULL;
 	new_mmapfile->fd=fd;
 	new_mmapfile->file_size=(unsigned long)(statbuf.st_size);
@@ -4366,8 +4366,8 @@
 
 	/* free memory */
 	if(temp_mmapfile->path!=NULL)
-		free(temp_mmapfile->path);
-	free(temp_mmapfile);
+		mt_free(temp_mmapfile->path);
+	mt_free(temp_mmapfile);
 	
 	return OK;
         }
@@ -4396,7 +4396,7 @@
 	len=(int)x-temp_mmapfile->current_position+1;
 
 	/* allocate memory for the new line */
-	if((buf=(char *)malloc(len+1))==NULL)
+	if((buf=(char *)mt_malloc(len+1))==NULL)
 		return NULL;
 
 	/* copy string to newly allocated memory and terminate the string */
@@ -4426,14 +4426,14 @@
 
 	while(1){
 
-		free(tempbuf);
+		mt_free(tempbuf);
 
 		if((tempbuf=mmap_fgets(temp_mmapfile))==NULL)
 			break;
 
 		if(buf==NULL){
 			len=strlen(tempbuf);
-			if((buf=(char *)malloc(len+1))==NULL)
+			if((buf=(char *)mt_malloc(len+1))==NULL)
 				break;
 			memcpy(buf,tempbuf,len);
 			buf[len]='\x0';
@@ -4441,7 +4441,7 @@
 		else{
 			len=strlen(tempbuf);
 			len2=strlen(buf);
-			if((buf=(char *)realloc(buf,len+len2+1))==NULL)
+			if((buf=(char *)mt_realloc(buf,len+len2+1))==NULL)
 				break;
 			strcat(buf,tempbuf);
 			len+=len2;
@@ -4453,7 +4453,7 @@
 			break;
 	        }
 
-	free(tempbuf);
+	mt_free(tempbuf);
 
 	return buf;
         }
@@ -4550,7 +4550,7 @@
 	service_result_buffer.tail=0;
 	service_result_buffer.items=0;
 	service_result_buffer.overflow=0L;
-	service_result_buffer.buffer=(void **)malloc(SERVICE_BUFFER_SLOTS*sizeof(service_message **));
+	service_result_buffer.buffer=(void **)mt_malloc(SERVICE_BUFFER_SLOTS*sizeof(service_message **));
 	if(service_result_buffer.buffer==NULL)
 		return ERROR;
 
@@ -4597,10 +4597,10 @@
 
 	/* release memory allocated to circular buffer */
 	for(x=service_result_buffer.tail;x!=service_result_buffer.head;x=(x+1) % SERVICE_BUFFER_SLOTS){
-		free(((service_message **)service_result_buffer.buffer)[x]);
+		mt_free(((service_message **)service_result_buffer.buffer)[x]);
 		((service_message **)service_result_buffer.buffer)[x]=NULL;
 	        }
-	free(service_result_buffer.buffer);
+	mt_free(service_result_buffer.buffer);
 
 	return;
         }
@@ -4616,7 +4616,7 @@
 	external_command_buffer.tail=0;
 	external_command_buffer.items=0;
 	external_command_buffer.overflow=0L;
-	external_command_buffer.buffer=(void **)malloc(COMMAND_BUFFER_SLOTS*sizeof(char **));
+	external_command_buffer.buffer=(void **)mt_malloc(COMMAND_BUFFER_SLOTS*sizeof(char **));
 	if(external_command_buffer.buffer==NULL)
 		return ERROR;
 
@@ -4663,10 +4663,10 @@
 
 	/* release memory allocated to circular buffer */
 	for(x=external_command_buffer.tail;x!=external_command_buffer.head;x=(x+1) % COMMAND_BUFFER_SLOTS){
-		free(((char **)external_command_buffer.buffer)[x]);
+		mt_free(((char **)external_command_buffer.buffer)[x]);
 		((char **)external_command_buffer.buffer)[x]=NULL;
 	        }
-	free(external_command_buffer.buffer);
+	mt_free(external_command_buffer.buffer);
 
 	return;
         }
@@ -4768,7 +4768,7 @@
 			if(read_result>=0){
 				
 				/* allocate memory for the message */
-				new_message=(service_message *)malloc(sizeof(service_message));
+				new_message=(service_message *)mt_malloc(sizeof(service_message));
 				if(new_message==NULL)
 					break;
 
@@ -4911,7 +4911,7 @@
 	if(external_command_buffer.items<COMMAND_BUFFER_SLOTS){
 
 		/* save the line in the buffer */
-		((char **)external_command_buffer.buffer)[external_command_buffer.head]=strdup(cmd);
+		((char **)external_command_buffer.buffer)[external_command_buffer.head]=mt_strdup(cmd);
 
 		/* increment the head counter and items */
 		external_command_buffer.head=(external_command_buffer.head + 1) % COMMAND_BUFFER_SLOTS;
@@ -4946,7 +4946,7 @@
 
 	/* allocate memory for the command string */
 	length=strlen(cmd)+16;
-	newcmd=(char *)malloc(length);
+	newcmd=(char *)mt_malloc(length);
 	if(newcmd==NULL)
 		return ERROR;
 
@@ -4964,7 +4964,7 @@
 	result=submit_external_command(newcmd,buffer_items);
 
 	/* free allocated memory */
-	free(newcmd);
+	mt_free(newcmd);
 
 	return result;
         }
@@ -5024,7 +5024,7 @@
 	this_event=event_list_high;
 	while(this_event!=NULL){
 		next_event=this_event->next;
-		free(this_event);
+		mt_free(this_event);
 		this_event=next_event;
 	        }
 
@@ -5035,7 +5035,7 @@
 	this_event=event_list_low;
 	while(this_event!=NULL){
 		next_event=this_event->next;
-		free(this_event);
+		mt_free(this_event);
 		this_event=next_event;
 	        }
 
@@ -5048,7 +5048,7 @@
 
 	/* free memory used by my_strtok() function */
 	if(original_my_strtok_buffer!=NULL)
-		free(original_my_strtok_buffer);
+		mt_free(original_my_strtok_buffer);
 
 	/* reset the my_strtok() buffers */
 	original_my_strtok_buffer=NULL;
@@ -5060,11 +5060,11 @@
 
 	/* free memory for global event handlers */
 	if(global_host_event_handler!=NULL){
-		free(global_host_event_handler);
+		mt_free(global_host_event_handler);
 		global_host_event_handler=NULL;
 	        }
 	if(global_service_event_handler!=NULL){
-		free(global_service_event_handler);
+		mt_free(global_service_event_handler);
 		global_service_event_handler=NULL;
 	        }
 
@@ -5081,32 +5081,32 @@
 
 	/* free obsessive compulsive commands */
 	if(ocsp_command!=NULL){
-		free(ocsp_command);
+		mt_free(ocsp_command);
 		ocsp_command=NULL;
 	        }
 	if(ochp_command!=NULL){
-		free(ochp_command);
+		mt_free(ochp_command);
 		ochp_command=NULL;
 	        }
 
 	/* free memory associated with macros */
 	for(x=0;x<MAX_COMMAND_ARGUMENTS;x++){
 		if(macro_argv[x]!=NULL){
-			free(macro_argv[x]);
+			mt_free(macro_argv[x]);
 			macro_argv[x]=NULL;
 		        }
 	        }
 
 	for(x=0;x<MAX_USER_MACROS;x++){
 		if(macro_user[x]!=NULL){
-			free(macro_user[x]);
+			mt_free(macro_user[x]);
 			macro_user[x]=NULL;
 		        }
 	        }
 
 	for(x=0;x<MACRO_X_COUNT;x++){
 		if(macro_x[x]!=NULL){
-			free(macro_x[x]);
+			mt_free(macro_x[x]);
 			macro_x[x]=NULL;
 		        }
 	        }
@@ -5116,51 +5116,51 @@
 
 	/* free illegal char strings */
 	if(illegal_object_chars!=NULL){
-		free(illegal_object_chars);
+		mt_free(illegal_object_chars);
 		illegal_object_chars=NULL;
 	        }
 	if(illegal_output_chars!=NULL){
-		free(illegal_output_chars);
+		mt_free(illegal_output_chars);
 		illegal_output_chars=NULL;
 	        }
 
 	/* free nagios user and group */
 	if(nagios_user!=NULL){
-		free(nagios_user);
+		mt_free(nagios_user);
 		nagios_user=NULL;
 	        }
 	if(nagios_group!=NULL){
-		free(nagios_group);
+		mt_free(nagios_group);
 		nagios_group=NULL;
 	        }
 
 	/* free file/path variables */
 	if(log_file!=NULL){
-		free(log_file);
+		mt_free(log_file);
 		log_file=NULL;
 	        }
 	if(temp_file!=NULL){
-		free(temp_file);
+		mt_free(temp_file);
 		temp_file=NULL;
 	        }
 	if(command_file!=NULL){
-		free(command_file);
+		mt_free(command_file);
 		command_file=NULL;
 	        }
 	if(lock_file!=NULL){
-		free(lock_file);
+		mt_free(lock_file);
 		lock_file=NULL;
 	        }
 	if(auth_file!=NULL){
-		free(auth_file);
+		mt_free(auth_file);
 		auth_file=NULL;
 	        }
 	if(p1_file!=NULL){
-		free(p1_file);
+		mt_free(p1_file);
 		p1_file=NULL;
 	        }
 	if(log_archive_path!=NULL){
-		free(log_archive_path);
+		mt_free(log_archive_path);
 		log_archive_path=NULL;
 	        }
 
@@ -5184,7 +5184,7 @@
 	temp_notification=notification_list;
 	while(temp_notification!=NULL){
 		next_notification=temp_notification->next;
-		free((void *)temp_notification);
+		mt_free((void *)temp_notification);
 		temp_notification=next_notification;
 	        }
 
@@ -5207,16 +5207,16 @@
 	printf("reset_variables() start\n");
 #endif
 
-	log_file=(char *)strdup(DEFAULT_LOG_FILE);
-	temp_file=(char *)strdup(DEFAULT_TEMP_FILE);
-	command_file=(char *)strdup(DEFAULT_COMMAND_FILE);
-	lock_file=(char *)strdup(DEFAULT_LOCK_FILE);
-	auth_file=(char *)strdup(DEFAULT_AUTH_FILE);
-	p1_file=(char *)strdup(DEFAULT_P1_FILE);
-	log_archive_path=(char *)strdup(DEFAULT_LOG_ARCHIVE_PATH);
+	log_file=(char *)mt_strdup(DEFAULT_LOG_FILE);
+	temp_file=(char *)mt_strdup(DEFAULT_TEMP_FILE);
+	command_file=(char *)mt_strdup(DEFAULT_COMMAND_FILE);
+	lock_file=(char *)mt_strdup(DEFAULT_LOCK_FILE);
+	auth_file=(char *)mt_strdup(DEFAULT_AUTH_FILE);
+	p1_file=(char *)mt_strdup(DEFAULT_P1_FILE);
+	log_archive_path=(char *)mt_strdup(DEFAULT_LOG_ARCHIVE_PATH);
 
-	nagios_user=(char *)strdup(DEFAULT_NAGIOS_USER);
-	nagios_group=(char *)strdup(DEFAULT_NAGIOS_GROUP);
+	nagios_user=(char *)mt_strdup(DEFAULT_NAGIOS_USER);
+	nagios_group=(char *)mt_strdup(DEFAULT_NAGIOS_GROUP);
 
 	use_regexp_matches=FALSE;
 	use_true_regexp_matching=FALSE;
diff -urN /home/exon/Nagios/common/comments.c ./common/comments.c
--- /home/exon/Nagios/common/comments.c	2004-11-15 09:28:06.000000000 +0100
+++ ./common/comments.c	2004-12-01 22:48:30.000000000 +0100
@@ -226,11 +226,11 @@
 			last_comment->next=next_comment;
 		
 		/* free memory */
-		free(this_comment->host_name);
-		free(this_comment->service_description);
-		free(this_comment->author);
-		free(this_comment->comment_data);
-		free(this_comment);
+		mt_free(this_comment->host_name);
+		mt_free(this_comment->service_description);
+		mt_free(this_comment->author);
+		mt_free(this_comment->comment_data);
+		mt_free(this_comment);
 
 		result=OK;
 	        }
@@ -386,7 +386,7 @@
 	if(comment_hashlist==NULL){
 		int i;
 
-		comment_hashlist=(comment **)malloc(sizeof(comment *)*COMMENT_HASHSLOTS);
+		comment_hashlist=(comment **)mt_malloc(sizeof(comment *)*COMMENT_HASHSLOTS);
 		if(comment_hashlist==NULL)
 			return 0;
 		
@@ -455,43 +455,43 @@
 		return ERROR;
 
 	/* allocate memory for the comment */
-	new_comment=(comment *)malloc(sizeof(comment));
+	new_comment=(comment *)mt_malloc(sizeof(comment));
 	if(new_comment==NULL)
 		return ERROR;
 
-	new_comment->host_name=strdup(host_name);
+	new_comment->host_name=mt_strdup(host_name);
 	if(new_comment->host_name==NULL){
-		free(new_comment);
+		mt_free(new_comment);
 		return ERROR;
 	        }
 
 	if(comment_type==SERVICE_COMMENT){
-		new_comment->service_description=strdup(svc_description);
+		new_comment->service_description=mt_strdup(svc_description);
 		if(new_comment->service_description==NULL){
-			free(new_comment->host_name);
-			free(new_comment);
+			mt_free(new_comment->host_name);
+			mt_free(new_comment);
 			return ERROR;
 		        }
 	        }
 	else
 		new_comment->service_description=NULL;
 
-	new_comment->author=strdup(author);
+	new_comment->author=mt_strdup(author);
 	if(new_comment->author==NULL){
 		if(new_comment->service_description!=NULL)
-			free(new_comment->service_description);
-		free(new_comment->host_name);
-		free(new_comment);
+			mt_free(new_comment->service_description);
+		mt_free(new_comment->host_name);
+		mt_free(new_comment);
 		return ERROR;
 	        }
 
-	new_comment->comment_data=strdup(comment_data);
+	new_comment->comment_data=mt_strdup(comment_data);
 	if(new_comment->comment_data==NULL){
-		free(new_comment->author);
+		mt_free(new_comment->author);
 		if(new_comment->service_description!=NULL)
-			free(new_comment->service_description);
-		free(new_comment->host_name);
-		free(new_comment);
+			mt_free(new_comment->service_description);
+		mt_free(new_comment->host_name);
+		mt_free(new_comment);
 		return ERROR;
 	        }
 
@@ -559,15 +559,15 @@
 	/* free memory for the comment list */
 	for(this_comment=comment_list;this_comment!=NULL;this_comment=next_comment){
 		next_comment=this_comment->next;
-		free(this_comment->host_name);
-		free(this_comment->service_description);
-		free(this_comment->author);
-		free(this_comment->comment_data);
-		free(this_comment);
+		mt_free(this_comment->host_name);
+		mt_free(this_comment->service_description);
+		mt_free(this_comment->author);
+		mt_free(this_comment->comment_data);
+		mt_free(this_comment);
 	        }
 
 	/* free hash list and reset list pointer */
-	free(comment_hashlist);
+	mt_free(comment_hashlist);
 	comment_hashlist=NULL;
 	comment_list=NULL;
 
diff -urN /home/exon/Nagios/common/downtime.c ./common/downtime.c
--- /home/exon/Nagios/common/downtime.c	2004-11-15 09:28:06.000000000 +0100
+++ ./common/downtime.c	2004-12-01 22:48:30.000000000 +0100
@@ -734,11 +734,11 @@
 			last_downtime->next=next_downtime;
 		
 		/* free memory */
-		free(this_downtime->host_name);
-		free(this_downtime->service_description);
-		free(this_downtime->author);
-		free(this_downtime->comment);
-		free(this_downtime);
+		mt_free(this_downtime->host_name);
+		mt_free(this_downtime->service_description);
+		mt_free(this_downtime->author);
+		mt_free(this_downtime->comment);
+		mt_free(this_downtime);
 
 		result=OK;
 	        }
@@ -850,21 +850,21 @@
 		return ERROR;
 
 	/* allocate memory for the downtime */
-	new_downtime=(scheduled_downtime *)malloc(sizeof(scheduled_downtime));
+	new_downtime=(scheduled_downtime *)mt_malloc(sizeof(scheduled_downtime));
 	if(new_downtime==NULL)
 		return ERROR;
 
-	new_downtime->host_name=strdup(host_name);
+	new_downtime->host_name=mt_strdup(host_name);
 	if(new_downtime->host_name==NULL){
-		free(new_downtime);
+		mt_free(new_downtime);
 		return ERROR;
 	        }
 
 	if(downtime_type==SERVICE_DOWNTIME){
-		new_downtime->service_description=strdup(svc_description);
+		new_downtime->service_description=mt_strdup(svc_description);
 		if(new_downtime->service_description==NULL){
-			free(new_downtime->host_name);
-			free(new_downtime);
+			mt_free(new_downtime->host_name);
+			mt_free(new_downtime);
 			return ERROR;
 		        }
 	        }
@@ -874,12 +874,12 @@
 	if(author==NULL)
 		new_downtime->author=NULL;
 	else
-		new_downtime->author=strdup(author);
+		new_downtime->author=mt_strdup(author);
 
 	if(comment_data==NULL)
 		new_downtime->comment=NULL;
 	else
-		new_downtime->comment=strdup(comment_data);
+		new_downtime->comment=mt_strdup(comment_data);
 
 	new_downtime->type=downtime_type;
 	new_downtime->entry_time=entry_time;
@@ -979,11 +979,11 @@
 	/* free memory for the scheduled_downtime list */
 	for(this_downtime=scheduled_downtime_list;this_downtime!=NULL;this_downtime=next_downtime){
 		next_downtime=this_downtime->next;
-		free(this_downtime->host_name);
-		free(this_downtime->service_description);
-		free(this_downtime->author);
-		free(this_downtime->comment);
-		free(this_downtime);
+		mt_free(this_downtime->host_name);
+		mt_free(this_downtime->service_description);
+		mt_free(this_downtime->author);
+		mt_free(this_downtime->comment);
+		mt_free(this_downtime);
 	        }
 
 	/* reset list pointer */
diff -urN /home/exon/Nagios/common/objects.c ./common/objects.c
--- /home/exon/Nagios/common/objects.c	2004-12-01 20:16:03.000000000 +0100
+++ ./common/objects.c	2004-12-01 22:48:30.000000000 +0100
@@ -121,7 +121,7 @@
 	if(host_hashlist==NULL){
 		int i;
 
-		host_hashlist=(host **)malloc(sizeof(host *)*HOST_HASHSLOTS);
+		host_hashlist=(host **)mt_malloc(sizeof(host *)*HOST_HASHSLOTS);
 		if(host_hashlist==NULL)
 			return 0;
 		
@@ -168,7 +168,7 @@
 	if(service_hashlist==NULL){
 		int i;
 
-		service_hashlist=(service **)malloc(sizeof(service *)*SERVICE_HASHSLOTS);
+		service_hashlist=(service **)mt_malloc(sizeof(service *)*SERVICE_HASHSLOTS);
 		if(service_hashlist==NULL)
 			return 0;
 		
@@ -216,7 +216,7 @@
 	if(command_hashlist==NULL){
 		int i;
 
-		command_hashlist=(command **)malloc(sizeof(command *)*COMMAND_HASHSLOTS);
+		command_hashlist=(command **)mt_malloc(sizeof(command *)*COMMAND_HASHSLOTS);
 		if(command_hashlist==NULL)
 			return 0;
 		
@@ -263,7 +263,7 @@
 	if(timeperiod_hashlist==NULL){
 		int i;
 
-		timeperiod_hashlist=(timeperiod **)malloc(sizeof(timeperiod *)*TIMEPERIOD_HASHSLOTS);
+		timeperiod_hashlist=(timeperiod **)mt_malloc(sizeof(timeperiod *)*TIMEPERIOD_HASHSLOTS);
 		if(timeperiod_hashlist==NULL)
 			return 0;
 		
@@ -310,7 +310,7 @@
 	if(contact_hashlist==NULL){
 		int i;
 
-		contact_hashlist=(contact **)malloc(sizeof(contact *)*CONTACT_HASHSLOTS);
+		contact_hashlist=(contact **)mt_malloc(sizeof(contact *)*CONTACT_HASHSLOTS);
 		if(contact_hashlist==NULL)
 			return 0;
 		
@@ -357,7 +357,7 @@
 	if(contactgroup_hashlist==NULL){
 		int i;
 
-		contactgroup_hashlist=(contactgroup **)malloc(sizeof(contactgroup *)*CONTACTGROUP_HASHSLOTS);
+		contactgroup_hashlist=(contactgroup **)mt_malloc(sizeof(contactgroup *)*CONTACTGROUP_HASHSLOTS);
 		if(contactgroup_hashlist==NULL)
 			return 0;
 		
@@ -404,7 +404,7 @@
 	if(hostgroup_hashlist==NULL){
 		int i;
 
-		hostgroup_hashlist=(hostgroup **)malloc(sizeof(hostgroup *)*HOSTGROUP_HASHSLOTS);
+		hostgroup_hashlist=(hostgroup **)mt_malloc(sizeof(hostgroup *)*HOSTGROUP_HASHSLOTS);
 		if(hostgroup_hashlist==NULL)
 			return 0;
 		
@@ -451,7 +451,7 @@
 	if(servicegroup_hashlist==NULL){
 		int i;
 
-		servicegroup_hashlist=(servicegroup **)malloc(sizeof(servicegroup *)*SERVICEGROUP_HASHSLOTS);
+		servicegroup_hashlist=(servicegroup **)mt_malloc(sizeof(servicegroup *)*SERVICEGROUP_HASHSLOTS);
 		if(servicegroup_hashlist==NULL)
 			return 0;
 		
@@ -499,7 +499,7 @@
 	if(hostextinfo_hashlist==NULL){
 		int i;
 
-		hostextinfo_hashlist=(hostextinfo **)malloc(sizeof(hostextinfo *)*HOSTEXTINFO_HASHSLOTS);
+		hostextinfo_hashlist=(hostextinfo **)mt_malloc(sizeof(hostextinfo *)*HOSTEXTINFO_HASHSLOTS);
 		if(hostextinfo_hashlist==NULL)
 			return 0;
 		
@@ -546,7 +546,7 @@
 	if(serviceextinfo_hashlist==NULL){
 		int i;
 
-		serviceextinfo_hashlist=(serviceextinfo **)malloc(sizeof(serviceextinfo *)*SERVICEEXTINFO_HASHSLOTS);
+		serviceextinfo_hashlist=(serviceextinfo **)mt_malloc(sizeof(serviceextinfo *)*SERVICEEXTINFO_HASHSLOTS);
 		if(serviceextinfo_hashlist==NULL)
 			return 0;
 		
@@ -592,7 +592,7 @@
 	if(hostdependency_hashlist==NULL){
 		int i;
 
-		hostdependency_hashlist=(hostdependency **)malloc(sizeof(hostdependency *)*HOSTDEPENDENCY_HASHSLOTS);
+		hostdependency_hashlist=(hostdependency **)mt_malloc(sizeof(hostdependency *)*HOSTDEPENDENCY_HASHSLOTS);
 		if(hostdependency_hashlist==NULL)
 			return 0;
 		
@@ -627,7 +627,7 @@
 	if(servicedependency_hashlist==NULL){
 		int i;
 
-		servicedependency_hashlist=(servicedependency **)malloc(sizeof(servicedependency *)*SERVICEDEPENDENCY_HASHSLOTS);
+		servicedependency_hashlist=(servicedependency **)mt_malloc(sizeof(servicedependency *)*SERVICEDEPENDENCY_HASHSLOTS);
 		if(servicedependency_hashlist==NULL)
 			return 0;
 		
@@ -663,7 +663,7 @@
 	if(hostescalation_hashlist==NULL){
 		int i;
 
-		hostescalation_hashlist=(hostescalation **)malloc(sizeof(hostescalation *)*HOSTESCALATION_HASHSLOTS);
+		hostescalation_hashlist=(hostescalation **)mt_malloc(sizeof(hostescalation *)*HOSTESCALATION_HASHSLOTS);
 		if(hostescalation_hashlist==NULL)
 			return 0;
 		
@@ -698,7 +698,7 @@
 	if(serviceescalation_hashlist==NULL){
 		int i;
 
-		serviceescalation_hashlist=(serviceescalation **)malloc(sizeof(serviceescalation *)*SERVICEESCALATION_HASHSLOTS);
+		serviceescalation_hashlist=(serviceescalation **)mt_malloc(sizeof(serviceescalation *)*SERVICEESCALATION_HASHSLOTS);
 		if(serviceescalation_hashlist==NULL)
 			return 0;
 		
@@ -773,7 +773,7 @@
 	        }
 
 	/* allocate memory for the new timeperiod */
-	new_timeperiod=malloc(sizeof(timeperiod));
+	new_timeperiod=mt_malloc(sizeof(timeperiod));
 	if(new_timeperiod==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for timeperiod '%s'\n",name);
@@ -782,25 +782,25 @@
 #endif
 		return NULL;
 	        }
-	new_timeperiod->name=(char *)malloc(strlen(name)+1);
+	new_timeperiod->name=(char *)mt_malloc(strlen(name)+1);
 	if(new_timeperiod->name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for timeperiod '%s' name\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_timeperiod);
+		mt_free(new_timeperiod);
 		return NULL;
 	        }
-	new_timeperiod->alias=(char *)malloc(strlen(alias)+1);
+	new_timeperiod->alias=(char *)mt_malloc(strlen(alias)+1);
 	if(new_timeperiod->alias==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for timeperiod '%s' alias\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_timeperiod->name);
-		free(new_timeperiod);
+		mt_free(new_timeperiod->name);
+		mt_free(new_timeperiod);
 		return NULL;
 	        }
 
@@ -821,9 +821,9 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_timeperiod->alias);
-		free(new_timeperiod->name);
-		free(new_timeperiod);
+		mt_free(new_timeperiod->alias);
+		mt_free(new_timeperiod->name);
+		mt_free(new_timeperiod);
 		return NULL;
 	        }
 
@@ -897,7 +897,7 @@
 	        }
 
 	/* allocate memory for the new time range */
-	new_timerange=malloc(sizeof(timerange));
+	new_timerange=mt_malloc(sizeof(timerange));
 	if(new_timerange==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for day %d timerange in timeperiod '%s'\n",day,period->name);
@@ -1164,7 +1164,7 @@
 
 
 	/* allocate memory for a new host */
-	new_host=(host *)malloc(sizeof(host));
+	new_host=(host *)mt_malloc(sizeof(host));
 	if(new_host==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s'\n",name);
@@ -1173,76 +1173,76 @@
 #endif
 		return NULL;
 	        }
-	new_host->name=strdup(name);
+	new_host->name=mt_strdup(name);
 	if(new_host->name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' name\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_host);
+		mt_free(new_host);
 		return NULL;
 	        }
-	new_host->alias=strdup(alias);
+	new_host->alias=mt_strdup(alias);
 	if(new_host->alias==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' alias\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_host->name);
-		free(new_host);
+		mt_free(new_host->name);
+		mt_free(new_host);
 		return NULL;
 	        }
-	new_host->address=strdup(address);
+	new_host->address=mt_strdup(address);
 	if(new_host->address==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' address\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_host->alias);
-		free(new_host->name);
-		free(new_host);
+		mt_free(new_host->alias);
+		mt_free(new_host->name);
+		mt_free(new_host);
 		return NULL;
 	        }
 	if(check_period!=NULL && strcmp(check_period,"")){
-		new_host->check_period=strdup(check_period);
+		new_host->check_period=mt_strdup(check_period);
 		if(new_host->check_period==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' check period\n",name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-			free(new_host->address);
-			free(new_host->alias);
-			free(new_host->name);
-			free(new_host);
+			mt_free(new_host->address);
+			mt_free(new_host->alias);
+			mt_free(new_host->name);
+			mt_free(new_host);
 			return NULL;
 		        }
 	        }
 	else
 		new_host->check_period=NULL;
 	if(notification_period!=NULL && strcmp(notification_period,"")){
-		new_host->notification_period=strdup(notification_period);
+		new_host->notification_period=mt_strdup(notification_period);
 		if(new_host->notification_period==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' notification period\n",name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-			free(new_host->check_period);
-			free(new_host->address);
-			free(new_host->alias);
-			free(new_host->name);
-			free(new_host);
+			mt_free(new_host->check_period);
+			mt_free(new_host->address);
+			mt_free(new_host->alias);
+			mt_free(new_host->name);
+			mt_free(new_host);
 			return NULL;
 		        }
 	        }
 	else
 		new_host->notification_period=NULL;
 	if(check_command!=NULL && strcmp(check_command,"")){
-		new_host->host_check_command=strdup(check_command);
+		new_host->host_check_command=mt_strdup(check_command);
 		if(new_host->host_check_command==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' check command\n",name);
@@ -1250,19 +1250,19 @@
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
 			if(new_host->notification_period!=NULL)
-				free(new_host->notification_period);
-			free(new_host->check_period);
-			free(new_host->address);
-			free(new_host->alias);
-			free(new_host->name);
-			free(new_host);
+				mt_free(new_host->notification_period);
+			mt_free(new_host->check_period);
+			mt_free(new_host->address);
+			mt_free(new_host->alias);
+			mt_free(new_host->name);
+			mt_free(new_host);
 			return NULL;
 		        }
 	        }
 	else
 		new_host->host_check_command=NULL;
 	if(event_handler!=NULL && strcmp(event_handler,"")){
-		new_host->event_handler=strdup(event_handler);
+		new_host->event_handler=mt_strdup(event_handler);
 		if(new_host->event_handler==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' event handler\n",name);
@@ -1270,21 +1270,21 @@
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
 			if(new_host->host_check_command!=NULL)
-				free(new_host->host_check_command);
+				mt_free(new_host->host_check_command);
 			if(new_host->notification_period!=NULL)
-				free(new_host->notification_period);
-			free(new_host->check_period);
-			free(new_host->address);
-			free(new_host->alias);
-			free(new_host->name);
-			free(new_host);
+				mt_free(new_host->notification_period);
+			mt_free(new_host->check_period);
+			mt_free(new_host->address);
+			mt_free(new_host->alias);
+			mt_free(new_host->name);
+			mt_free(new_host);
 			return NULL;
 	                }
 	        }
 	else
 		new_host->event_handler=NULL;
 	if(failure_prediction_options!=NULL && strcmp(failure_prediction_options,"")){
-		new_host->failure_prediction_options=strdup(failure_prediction_options);
+		new_host->failure_prediction_options=mt_strdup(failure_prediction_options);
 		if(new_host->failure_prediction_options==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' failure prediction options\n",name);
@@ -1292,16 +1292,16 @@
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
 			if(new_host->event_handler!=NULL)
-				free(new_host->event_handler);
+				mt_free(new_host->event_handler);
 			if(new_host->host_check_command!=NULL)
-				free(new_host->host_check_command);
+				mt_free(new_host->host_check_command);
 			if(new_host->notification_period!=NULL)
-				free(new_host->notification_period);
-			free(new_host->check_period);
-			free(new_host->address);
-			free(new_host->alias);
-			free(new_host->name);
-			free(new_host);
+				mt_free(new_host->notification_period);
+			mt_free(new_host->check_period);
+			mt_free(new_host->address);
+			mt_free(new_host->alias);
+			mt_free(new_host->name);
+			mt_free(new_host);
 			return NULL;
 	                }
 	        }
@@ -1379,7 +1379,7 @@
 	new_host->modified_attributes=MODATTR_NONE;
 
 	/* allocate new plugin output buffer */
-	new_host->plugin_output=(char *)malloc(MAX_PLUGINOUTPUT_LENGTH);
+	new_host->plugin_output=(char *)mt_malloc(MAX_PLUGINOUTPUT_LENGTH);
 	if(new_host->plugin_output==NULL){
 
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' plugin output buffer\n",name);
@@ -1387,23 +1387,23 @@
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 
 		if(new_host->failure_prediction_options!=NULL)
-			free(new_host->failure_prediction_options);
+			mt_free(new_host->failure_prediction_options);
 		if(new_host->event_handler!=NULL)
-			free(new_host->event_handler);
+			mt_free(new_host->event_handler);
 		if(new_host->host_check_command!=NULL)
-			free(new_host->host_check_command);
+			mt_free(new_host->host_check_command);
 		if(new_host->notification_period!=NULL)
-			free(new_host->notification_period);
-		free(new_host->address);
-		free(new_host->alias);
-		free(new_host->name);
-		free(new_host);
+			mt_free(new_host->notification_period);
+		mt_free(new_host->address);
+		mt_free(new_host->alias);
+		mt_free(new_host->name);
+		mt_free(new_host);
 		return NULL;
 	        }
 	strcpy(new_host->plugin_output,"");
 
 	/* allocate new performance data buffer */
-	new_host->perf_data=(char *)malloc(MAX_PLUGINOUTPUT_LENGTH);
+	new_host->perf_data=(char *)mt_malloc(MAX_PLUGINOUTPUT_LENGTH);
 	if(new_host->perf_data==NULL){
 
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' performance data buffer\n",name);
@@ -1411,18 +1411,18 @@
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 
 		if(new_host->failure_prediction_options!=NULL)
-			free(new_host->failure_prediction_options);
+			mt_free(new_host->failure_prediction_options);
 		if(new_host->event_handler!=NULL)
-			free(new_host->event_handler);
+			mt_free(new_host->event_handler);
 		if(new_host->host_check_command!=NULL)
-			free(new_host->host_check_command);
+			mt_free(new_host->host_check_command);
 		if(new_host->notification_period!=NULL)
-			free(new_host->notification_period);
-		free(new_host->address);
-		free(new_host->alias);
-		free(new_host->name);
-		free(new_host->plugin_output);
-		free(new_host);
+			mt_free(new_host->notification_period);
+		mt_free(new_host->address);
+		mt_free(new_host->alias);
+		mt_free(new_host->name);
+		mt_free(new_host->plugin_output);
+		mt_free(new_host);
 		return NULL;
 	        }
 	strcpy(new_host->perf_data,"");
@@ -1439,23 +1439,23 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 		
-		free(new_host->plugin_output);
+		mt_free(new_host->plugin_output);
 		if(new_host->perf_data)
-			free(new_host->perf_data);
+			mt_free(new_host->perf_data);
 #endif
 
 		if(new_host->failure_prediction_options!=NULL)
-			free(new_host->failure_prediction_options);
+			mt_free(new_host->failure_prediction_options);
 		if(new_host->event_handler!=NULL)
-			free(new_host->event_handler);
+			mt_free(new_host->event_handler);
 		if(new_host->host_check_command!=NULL)
-			free(new_host->host_check_command);
+			mt_free(new_host->host_check_command);
 		if(new_host->notification_period!=NULL)
-			free(new_host->notification_period);
-		free(new_host->address);
-		free(new_host->alias);
-		free(new_host->name);
-		free(new_host);
+			mt_free(new_host->notification_period);
+		mt_free(new_host->address);
+		mt_free(new_host->alias);
+		mt_free(new_host->name);
+		mt_free(new_host);
 		return NULL;
 	        }
 
@@ -1539,7 +1539,7 @@
 	        }
 
 	/* allocate memory */
-	new_hostsmember=(hostsmember *)malloc(sizeof(hostsmember));
+	new_hostsmember=(hostsmember *)mt_malloc(sizeof(hostsmember));
 	if(new_hostsmember==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' parent host (%s)\n",hst->name,host_name);
@@ -1549,14 +1549,14 @@
 		return NULL;
 	        }
 
-	new_hostsmember->host_name=strdup(host_name);
+	new_hostsmember->host_name=mt_strdup(host_name);
 	if(new_hostsmember->host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' parent host (%s) name\n",hst->name,host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostsmember);
+		mt_free(new_hostsmember);
 		return NULL;
 	        }
 
@@ -1605,7 +1605,7 @@
 	        }
 
 	/* allocate memory for a new member */
-	new_contactgroupsmember=malloc(sizeof(contactgroupsmember));
+	new_contactgroupsmember=mt_malloc(sizeof(contactgroupsmember));
 	if(new_contactgroupsmember==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' contactgroup member '%s'\n",hst->name,group_name);
@@ -1614,14 +1614,14 @@
 #endif
 		return NULL;
 	        }
-	new_contactgroupsmember->group_name=strdup(group_name);
+	new_contactgroupsmember->group_name=mt_strdup(group_name);
 	if(new_contactgroupsmember->group_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' contactgroup member '%s' name\n",hst->name,group_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contactgroupsmember);
+		mt_free(new_contactgroupsmember);
 		return NULL;
 	        }
 
@@ -1684,7 +1684,7 @@
 	        }
 
 	/* allocate memory */
-	new_hostgroup=(hostgroup *)malloc(sizeof(hostgroup));
+	new_hostgroup=(hostgroup *)mt_malloc(sizeof(hostgroup));
 	if(new_hostgroup==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for hostgroup '%s'\n",name);
@@ -1693,25 +1693,25 @@
 #endif
 		return NULL;
 	        }
-	new_hostgroup->group_name=strdup(name);
+	new_hostgroup->group_name=mt_strdup(name);
 	if(new_hostgroup->group_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for hostgroup '%s' name\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostgroup);
+		mt_free(new_hostgroup);
 		return NULL;
 	        }
-	new_hostgroup->alias=strdup(alias);
+	new_hostgroup->alias=mt_strdup(alias);
 	if(new_hostgroup->alias==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for hostgroup '%s' alias\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostgroup->group_name);
-		free(new_hostgroup);
+		mt_free(new_hostgroup->group_name);
+		mt_free(new_hostgroup);
 		return NULL;
 	        }
 
@@ -1728,9 +1728,9 @@
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
 
-		free(new_hostgroup->group_name);
-		free(new_hostgroup->alias);
-		free(new_hostgroup);
+		mt_free(new_hostgroup->group_name);
+		mt_free(new_hostgroup->alias);
+		mt_free(new_hostgroup);
 		return NULL;
 	        }
 
@@ -1798,7 +1798,7 @@
 	        }
 
 	/* allocate memory for a new member */
-	new_member=malloc(sizeof(hostgroupmember));
+	new_member=mt_malloc(sizeof(hostgroupmember));
 	if(new_member==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for hostgroup '%s' member '%s'\n",temp_hostgroup->group_name,host_name);
@@ -1807,14 +1807,14 @@
 #endif
 		return NULL;
 	        }
-	new_member->host_name=strdup(host_name);
+	new_member->host_name=mt_strdup(host_name);
 	if(new_member->host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for hostgroup '%s' member '%s' name\n",temp_hostgroup->group_name,host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_member);
+		mt_free(new_member);
 		return NULL;
 	        }
 
@@ -1896,7 +1896,7 @@
 	        }
 
 	/* allocate memory */
-	new_servicegroup=(servicegroup *)malloc(sizeof(servicegroup));
+	new_servicegroup=(servicegroup *)mt_malloc(sizeof(servicegroup));
 	if(new_servicegroup==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for servicegroup '%s'\n",name);
@@ -1905,25 +1905,25 @@
 #endif
 		return NULL;
 	        }
-	new_servicegroup->group_name=strdup(name);
+	new_servicegroup->group_name=mt_strdup(name);
 	if(new_servicegroup->group_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for servicegroup '%s' name\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_servicegroup);
+		mt_free(new_servicegroup);
 		return NULL;
 	        }
-	new_servicegroup->alias=strdup(alias);
+	new_servicegroup->alias=mt_strdup(alias);
 	if(new_servicegroup->alias==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for servicegroup '%s' alias\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_servicegroup->group_name);
-		free(new_servicegroup);
+		mt_free(new_servicegroup->group_name);
+		mt_free(new_servicegroup);
 		return NULL;
 	        }
 
@@ -1940,9 +1940,9 @@
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
 
-		free(new_servicegroup->group_name);
-		free(new_servicegroup->alias);
-		free(new_servicegroup);
+		mt_free(new_servicegroup->group_name);
+		mt_free(new_servicegroup->alias);
+		mt_free(new_servicegroup);
 		return NULL;
 	        }
 
@@ -2011,7 +2011,7 @@
 	        }
 
 	/* allocate memory for a new member */
-	new_member=malloc(sizeof(servicegroupmember));
+	new_member=mt_malloc(sizeof(servicegroupmember));
 	if(new_member==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for servicegroup '%s' member (service '%s' on host '%s')\n",temp_servicegroup->group_name,host_name,svc_description);
@@ -2020,25 +2020,25 @@
 #endif
 		return NULL;
 	        }
-	new_member->host_name=strdup(host_name);
+	new_member->host_name=mt_strdup(host_name);
 	if(new_member->host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for servicegroup '%s' member (service '%s' on host '%s') name\n",temp_servicegroup->group_name,host_name,svc_description);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_member);
+		mt_free(new_member);
 		return NULL;
 	        }
-	new_member->service_description=strdup(svc_description);
+	new_member->service_description=mt_strdup(svc_description);
 	if(new_member->service_description==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for servicegroup '%s' member (service '%s' on host '%s') name\n",temp_servicegroup->group_name,host_name,svc_description);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_member->host_name);
-		free(new_member);
+		mt_free(new_member->host_name);
+		mt_free(new_member);
 		return NULL;
 	        }
 
@@ -2219,7 +2219,7 @@
 	        }
 
 	/* allocate memory for a new contact */
-	new_contact=(contact *)malloc(sizeof(contact));
+	new_contact=(contact *)mt_malloc(sizeof(contact));
 	if(new_contact==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s'\n",name);
@@ -2228,98 +2228,98 @@
 #endif
 		return NULL;
 	        }
-	new_contact->name=strdup(name);
+	new_contact->name=mt_strdup(name);
 	if(new_contact->name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' name\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contact);
+		mt_free(new_contact);
 		return NULL;
 	        }
-	new_contact->alias=strdup(alias);
+	new_contact->alias=mt_strdup(alias);
 	if(new_contact->alias==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' alias\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contact->name);
-		free(new_contact);
+		mt_free(new_contact->name);
+		mt_free(new_contact);
 		return NULL;
 	        }
 	if(email!=NULL && strcmp(email,"")){
-		new_contact->email=strdup(email);
+		new_contact->email=mt_strdup(email);
 		if(new_contact->email==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' email address\n",name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contact->name);
-			free(new_contact->alias);
-			free(new_contact);
+		mt_free(new_contact->name);
+			mt_free(new_contact->alias);
+			mt_free(new_contact);
 			return NULL;
 		        }
 	        }
 	else
 		new_contact->email=NULL;
 	if(pager!=NULL && strcmp(pager,"")){
-		new_contact->pager=strdup(pager);
+		new_contact->pager=mt_strdup(pager);
 		if(new_contact->pager==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' pager number\n",name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-			free(new_contact->name);
-			free(new_contact->alias);
+			mt_free(new_contact->name);
+			mt_free(new_contact->alias);
 			if(new_contact->email!=NULL)
-				free(new_contact->email);
-			free(new_contact);
+				mt_free(new_contact->email);
+			mt_free(new_contact);
 			return NULL;
 		        }
 	        }
 	else
 		new_contact->pager=NULL;
 	if(svc_notification_period!=NULL && strcmp(svc_notification_period,"")){
-		new_contact->service_notification_period=strdup(svc_notification_period);
+		new_contact->service_notification_period=mt_strdup(svc_notification_period);
 		if(new_contact->service_notification_period==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' service notification period\n",name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-			free(new_contact->name);
-			free(new_contact->alias);
+			mt_free(new_contact->name);
+			mt_free(new_contact->alias);
 			if(new_contact->email!=NULL)
-				free(new_contact->email);
+				mt_free(new_contact->email);
 			if(new_contact->pager!=NULL)
-				free(new_contact->pager);
-			free(new_contact);
+				mt_free(new_contact->pager);
+			mt_free(new_contact);
 			return NULL;
 		        }
 	        }
 	else 
 		new_contact->service_notification_period=NULL;
 	if(host_notification_period!=NULL && strcmp(host_notification_period,"")){
-		new_contact->host_notification_period=strdup(host_notification_period);
+		new_contact->host_notification_period=mt_strdup(host_notification_period);
 		if(new_contact->host_notification_period==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' host notification period\n",name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-			free(new_contact->name);
-			free(new_contact->alias);
+			mt_free(new_contact->name);
+			mt_free(new_contact->alias);
 			if(new_contact->email!=NULL)
-				free(new_contact->email);
+				mt_free(new_contact->email);
 			if(new_contact->pager!=NULL)
-				free(new_contact->pager);
+				mt_free(new_contact->pager);
 			if(new_contact->service_notification_period!=NULL)
-				free(new_contact->service_notification_period);
-			free(new_contact);
+				mt_free(new_contact->service_notification_period);
+			mt_free(new_contact);
 			return NULL;
 		        }
 	        }
@@ -2331,20 +2331,20 @@
 		new_contact->address[x]=NULL;
 		if(addresses[x]!=NULL){
 			strip(addresses[x]);
-			new_contact->address[x]=strdup(addresses[x]);
+			new_contact->address[x]=mt_strdup(addresses[x]);
 			if(new_contact->address[x]==NULL){
 #ifdef NSCORE
 				snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' address #%d\n",name,x);
 				temp_buffer[sizeof(temp_buffer)-1]='\x0';
 				write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-				free(new_contact->name);
-				free(new_contact->alias);
-				free(new_contact->email);
-				free(new_contact->pager);
-				free(new_contact->service_notification_period);
-				free(new_contact->host_notification_period);
-				free(new_contact);
+				mt_free(new_contact->name);
+				mt_free(new_contact->alias);
+				mt_free(new_contact->email);
+				mt_free(new_contact->pager);
+				mt_free(new_contact->service_notification_period);
+				mt_free(new_contact->host_notification_period);
+				mt_free(new_contact);
 				return NULL;
 		                }
 		        }
@@ -2374,14 +2374,14 @@
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
 		for(x=0;x<MAX_CONTACT_ADDRESSES;x++)
-			free(new_contact->address[x]);
-		free(new_contact->name);
-		free(new_contact->alias);
-		free(new_contact->email);
-		free(new_contact->pager);
-		free(new_contact->service_notification_period);
-		free(new_contact->host_notification_period);
-		free(new_contact);
+			mt_free(new_contact->address[x]);
+		mt_free(new_contact->name);
+		mt_free(new_contact->alias);
+		mt_free(new_contact->email);
+		mt_free(new_contact->pager);
+		mt_free(new_contact->service_notification_period);
+		mt_free(new_contact->host_notification_period);
+		mt_free(new_contact);
 
 		return NULL;
 	        }
@@ -2452,7 +2452,7 @@
 	        }
 
 	/* allocate memory */
-	new_commandsmember=malloc(sizeof(commandsmember));
+	new_commandsmember=mt_malloc(sizeof(commandsmember));
 	if(new_commandsmember==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' host notification command '%s'\n",cntct->name,command_name);
@@ -2462,14 +2462,14 @@
 		return NULL;
 	        }
 
-	new_commandsmember->command=strdup(command_name);
+	new_commandsmember->command=mt_strdup(command_name);
 	if(new_commandsmember->command==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' host notification command '%s' name\n",cntct->name,command_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_commandsmember);
+		mt_free(new_commandsmember);
 		return NULL;
 	        }
 
@@ -2519,7 +2519,7 @@
 	        }
 
 	/* allocate memory */
-	new_commandsmember=malloc(sizeof(commandsmember));
+	new_commandsmember=mt_malloc(sizeof(commandsmember));
 	if(new_commandsmember==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' service notification command '%s'\n",cntct->name,command_name);
@@ -2529,14 +2529,14 @@
 		return NULL;
 	        }
 
-	new_commandsmember->command=strdup(command_name);
+	new_commandsmember->command=mt_strdup(command_name);
 	if(new_commandsmember->command==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact '%s' service notification command '%s' name\n",cntct->name,command_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_commandsmember);
+		mt_free(new_commandsmember);
 		return NULL;
 	        }
 
@@ -2599,7 +2599,7 @@
 	        }
 
 	/* allocate memory for a new contactgroup entry */
-	new_contactgroup=malloc(sizeof(contactgroup));
+	new_contactgroup=mt_malloc(sizeof(contactgroup));
 	if(new_contactgroup==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contactgroup '%s'\n",name);
@@ -2608,25 +2608,25 @@
 #endif
 		return NULL;
 	        }
-	new_contactgroup->group_name=strdup(name);
+	new_contactgroup->group_name=mt_strdup(name);
 	if(new_contactgroup->group_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contactgroup '%s' name\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contactgroup);
+		mt_free(new_contactgroup);
 		return NULL;
 	        }
-	new_contactgroup->alias=strdup(alias);
+	new_contactgroup->alias=mt_strdup(alias);
 	if(new_contactgroup->alias==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contactgroup '%s' alias\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contactgroup->group_name);
-		free(new_contactgroup);
+		mt_free(new_contactgroup->group_name);
+		mt_free(new_contactgroup);
 		return NULL;
 	        }
 
@@ -2642,9 +2642,9 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contactgroup->alias);
-		free(new_contactgroup->group_name);
-		free(new_contactgroup);
+		mt_free(new_contactgroup->alias);
+		mt_free(new_contactgroup->group_name);
+		mt_free(new_contactgroup);
 
 		return NULL;
 	        }
@@ -2712,7 +2712,7 @@
 	        }
 
 	/* allocate memory for a new member */
-	new_contactgroupmember=malloc(sizeof(contactgroupmember));
+	new_contactgroupmember=mt_malloc(sizeof(contactgroupmember));
 	if(new_contactgroupmember==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contactgroup '%s' contact '%s'\n",grp->group_name,contact_name);
@@ -2721,14 +2721,14 @@
 #endif
 		return NULL;
 	        }
-	new_contactgroupmember->contact_name=strdup(contact_name);
+	new_contactgroupmember->contact_name=mt_strdup(contact_name);
 	if(new_contactgroupmember->contact_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contactgroup '%s' contact '%s' name\n",grp->group_name,contact_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contactgroupmember);
+		mt_free(new_contactgroupmember);
 		return NULL;
 	        }
 	
@@ -3007,7 +3007,7 @@
 
 
 	/* allocate memory */
-	new_service=(service *)malloc(sizeof(service));
+	new_service=(service *)mt_malloc(sizeof(service));
 	if(new_service==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s'\n",description,host_name);
@@ -3016,58 +3016,58 @@
 #endif
 		return NULL;
 	        }
-	new_service->host_name=strdup(host_name);
+	new_service->host_name=mt_strdup(host_name);
 	if(new_service->host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' name\n",description,host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_service);
+		mt_free(new_service);
 		return NULL;
 	        }
-	new_service->description=strdup(description);
+	new_service->description=mt_strdup(description);
 	if(new_service->description==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' description\n",description,host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_service->host_name);
-		free(new_service);
+		mt_free(new_service->host_name);
+		mt_free(new_service);
 		return NULL;
 	        }
-	new_service->service_check_command=strdup(check_command);
+	new_service->service_check_command=mt_strdup(check_command);
 	if(new_service->service_check_command==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' check command\n",description,host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_service->description);
-		free(new_service->host_name);
-		free(new_service);
+		mt_free(new_service->description);
+		mt_free(new_service->host_name);
+		mt_free(new_service);
 		return NULL;
 	        }
 	if(event_handler!=NULL && strcmp(event_handler,"")){
-		new_service->event_handler=strdup(event_handler);
+		new_service->event_handler=mt_strdup(event_handler);
 		if(new_service->event_handler==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' event handler\n",description,host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-			free(new_service->service_check_command);
-			free(new_service->description);
-			free(new_service->host_name);
-			free(new_service);
+			mt_free(new_service->service_check_command);
+			mt_free(new_service->description);
+			mt_free(new_service->host_name);
+			mt_free(new_service);
 			return NULL;
 		        }
 	        }
 	else
 		new_service->event_handler=NULL;
 	if(notification_period!=NULL && strcmp(notification_period,"")){
-		new_service->notification_period=strdup(notification_period);
+		new_service->notification_period=mt_strdup(notification_period);
 		if(new_service->notification_period==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' notification period\n",description,host_name);
@@ -3075,18 +3075,18 @@
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
 			if(new_service->event_handler!=NULL)
-				free(new_service->event_handler);
-			free(new_service->service_check_command);
-			free(new_service->description);
-			free(new_service->host_name);
-			free(new_service);
+				mt_free(new_service->event_handler);
+			mt_free(new_service->service_check_command);
+			mt_free(new_service->description);
+			mt_free(new_service->host_name);
+			mt_free(new_service);
 			return NULL;
 		        }
 	        }
 	else
 		new_service->notification_period=NULL;
 	if(check_period!=NULL && strcmp(check_period,"")){
-		new_service->check_period=strdup(check_period);
+		new_service->check_period=mt_strdup(check_period);
 		if(new_service->check_period==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' check period\n",description,host_name);
@@ -3094,20 +3094,20 @@
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
 			if(new_service->notification_period!=NULL)
-				free(new_service->notification_period);
+				mt_free(new_service->notification_period);
 			if(new_service->event_handler!=NULL)
-				free(new_service->event_handler);
-			free(new_service->service_check_command);
-			free(new_service->description);
-			free(new_service->host_name);
-			free(new_service);
+				mt_free(new_service->event_handler);
+			mt_free(new_service->service_check_command);
+			mt_free(new_service->description);
+			mt_free(new_service->host_name);
+			mt_free(new_service);
 			return NULL;
 		        }
 	        }
 	else
 		new_service->check_period=NULL;
 	if(failure_prediction_options!=NULL && strcmp(failure_prediction_options,"")){
-		new_service->failure_prediction_options=strdup(failure_prediction_options);
+		new_service->failure_prediction_options=mt_strdup(failure_prediction_options);
 		if(new_service->failure_prediction_options==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' failure prediction options\n",description,host_name);
@@ -3115,15 +3115,15 @@
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
 			if(new_service->check_period!=NULL)
-				free(new_service->check_period);
+				mt_free(new_service->check_period);
 			if(new_service->notification_period!=NULL)
-				free(new_service->notification_period);
+				mt_free(new_service->notification_period);
 			if(new_service->event_handler!=NULL)
-				free(new_service->event_handler);
-			free(new_service->service_check_command);
-			free(new_service->description);
-			free(new_service->host_name);
-			free(new_service);
+				mt_free(new_service->event_handler);
+			mt_free(new_service->service_check_command);
+			mt_free(new_service->description);
+			mt_free(new_service->host_name);
+			mt_free(new_service);
 			return NULL;
 		        }
 	        }
@@ -3209,7 +3209,7 @@
 	new_service->modified_attributes=MODATTR_NONE;
 
 	/* allocate new plugin output buffer */
-	new_service->plugin_output=(char *)malloc(MAX_PLUGINOUTPUT_LENGTH);
+	new_service->plugin_output=(char *)mt_malloc(MAX_PLUGINOUTPUT_LENGTH);
 	if(new_service->plugin_output==NULL){
 
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' plugin output buffer\n",description,host_name);
@@ -3217,21 +3217,21 @@
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 
 		if(new_service->failure_prediction_options!=NULL)
-			free(new_service->failure_prediction_options);
+			mt_free(new_service->failure_prediction_options);
 		if(new_service->notification_period!=NULL)
-			free(new_service->notification_period);
+			mt_free(new_service->notification_period);
 		if(new_service->event_handler!=NULL)
-			free(new_service->event_handler);
-		free(new_service->service_check_command);
-		free(new_service->description);
-		free(new_service->host_name);
-		free(new_service);
+			mt_free(new_service->event_handler);
+		mt_free(new_service->service_check_command);
+		mt_free(new_service->description);
+		mt_free(new_service->host_name);
+		mt_free(new_service);
 		return NULL;
 	        }
 	strcpy(new_service->plugin_output,"(Service assumed to be ok)");
 
 	/* allocate new performance data buffer */
-	new_service->perf_data=(char *)malloc(MAX_PLUGINOUTPUT_LENGTH);
+	new_service->perf_data=(char *)mt_malloc(MAX_PLUGINOUTPUT_LENGTH);
 	if(new_service->perf_data==NULL){
 
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' performance data buffer\n",description,host_name);
@@ -3239,16 +3239,16 @@
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 
 		if(new_service->failure_prediction_options!=NULL)
-			free(new_service->failure_prediction_options);
+			mt_free(new_service->failure_prediction_options);
 		if(new_service->notification_period!=NULL)
-			free(new_service->notification_period);
+			mt_free(new_service->notification_period);
 		if(new_service->event_handler!=NULL)
-			free(new_service->event_handler);
-		free(new_service->service_check_command);
-		free(new_service->description);
-		free(new_service->host_name);
-		free(new_service->plugin_output);
-		free(new_service);
+			mt_free(new_service->event_handler);
+		mt_free(new_service->service_check_command);
+		mt_free(new_service->description);
+		mt_free(new_service->host_name);
+		mt_free(new_service->plugin_output);
+		mt_free(new_service);
 		return NULL;
 	        }
 	strcpy(new_service->perf_data,"");
@@ -3266,23 +3266,23 @@
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 
 		if(new_service->perf_data!=NULL)
-			free(new_service->perf_data);
+			mt_free(new_service->perf_data);
 		if(new_service->plugin_output)
-			free(new_service->plugin_output);
+			mt_free(new_service->plugin_output);
 #endif
 		if(new_service->failure_prediction_options!=NULL)
-			free(new_service->failure_prediction_options);
+			mt_free(new_service->failure_prediction_options);
 		if(new_service->notification_period!=NULL)
-			free(new_service->notification_period);
+			mt_free(new_service->notification_period);
 		if(new_service->event_handler!=NULL)
-			free(new_service->event_handler);
+			mt_free(new_service->event_handler);
 		if(new_service->service_check_command)
-			free(new_service->service_check_command);
+			mt_free(new_service->service_check_command);
 		if(new_service->description)
-			free(new_service->description);
+			mt_free(new_service->description);
 		if(new_service->host_name)
-			free(new_service->host_name);
-		free(new_service);
+			mt_free(new_service->host_name);
+		mt_free(new_service);
 		return NULL;
 	        }
 
@@ -3359,7 +3359,7 @@
 	        }
 
 	/* allocate memory for the contactgroups member */
-	new_contactgroupsmember=malloc(sizeof(contactgroupsmember));
+	new_contactgroupsmember=mt_malloc(sizeof(contactgroupsmember));
 	if(new_contactgroupsmember==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact group '%s' for service '%s' on host '%s'\n",group_name,svc->description,svc->host_name);
@@ -3368,14 +3368,14 @@
 #endif
 		return NULL;
 	        }
-	new_contactgroupsmember->group_name=strdup(group_name);
+	new_contactgroupsmember->group_name=mt_strdup(group_name);
 	if(new_contactgroupsmember->group_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact group '%s' name for service '%s' on host '%s'\n",group_name,svc->description,svc->host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contactgroupsmember);
+		mt_free(new_contactgroupsmember);
 		return NULL;
 	        }
 
@@ -3439,7 +3439,7 @@
 	        }
 
 	/* allocate memory for the new command */
-	new_command=(command *)malloc(sizeof(command));
+	new_command=(command *)mt_malloc(sizeof(command));
 	if(new_command==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for command '%s'\n",name);
@@ -3448,25 +3448,25 @@
 #endif
 		return NULL;
 	        }
-	new_command->name=strdup(name);
+	new_command->name=mt_strdup(name);
 	if(new_command->name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for command '%s' name\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_command);
+		mt_free(new_command);
 		return NULL;
 	        }
-	new_command->command_line=strdup(value);
+	new_command->command_line=mt_strdup(value);
 	if(new_command->command_line==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for command '%s' alias\n",name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_command->name);
-		free(new_command);
+		mt_free(new_command->name);
+		mt_free(new_command);
 		return NULL;
 	        }
 
@@ -3480,8 +3480,8 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_command->name);
-		free(new_command);
+		mt_free(new_command->name);
+		mt_free(new_command);
 		return NULL;
 	        }
 
@@ -3558,7 +3558,7 @@
 	        }
 
 	/* allocate memory for a new service escalation entry */
-	new_serviceescalation=malloc(sizeof(serviceescalation));
+	new_serviceescalation=mt_malloc(sizeof(serviceescalation));
 	if(new_serviceescalation==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' escalation\n",description,host_name);
@@ -3567,40 +3567,40 @@
 #endif
 		return NULL;
 	        }
-	new_serviceescalation->host_name=strdup(host_name);
+	new_serviceescalation->host_name=mt_strdup(host_name);
 	if(new_serviceescalation->host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' escalation host name\n",description,host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_serviceescalation);
+		mt_free(new_serviceescalation);
 		return NULL;
 	        }
-	new_serviceescalation->description=strdup(description);
+	new_serviceescalation->description=mt_strdup(description);
 	if(new_serviceescalation->description==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' escalation description\n",description,host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_serviceescalation->host_name);
-		free(new_serviceescalation);
+		mt_free(new_serviceescalation->host_name);
+		mt_free(new_serviceescalation);
 		return NULL;
 	        }
 	if(escalation_period==NULL)
 		new_serviceescalation->escalation_period=NULL;
 	else{
-		new_serviceescalation->escalation_period=strdup(escalation_period);
+		new_serviceescalation->escalation_period=mt_strdup(escalation_period);
 		if(new_serviceescalation->escalation_period==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' escalation period\n",description,host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-			free(new_serviceescalation->host_name);
-			free(new_serviceescalation->description);
-			free(new_serviceescalation);
+			mt_free(new_serviceescalation->host_name);
+			mt_free(new_serviceescalation->description);
+			mt_free(new_serviceescalation);
 			return NULL;
 		        }
 	        }
@@ -3625,10 +3625,10 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_serviceescalation->host_name);
-		free(new_serviceescalation->description);
-		free(new_serviceescalation->escalation_period);
-		free(new_serviceescalation);
+		mt_free(new_serviceescalation->host_name);
+		mt_free(new_serviceescalation->description);
+		mt_free(new_serviceescalation->escalation_period);
+		mt_free(new_serviceescalation);
 		return NULL;
 	        }
 
@@ -3698,7 +3698,7 @@
 	        }
 
 	/* allocate memory for the contactgroups member */
-	new_contactgroupsmember=(contactgroupsmember *)malloc(sizeof(contactgroupsmember));
+	new_contactgroupsmember=(contactgroupsmember *)mt_malloc(sizeof(contactgroupsmember));
 	if(new_contactgroupsmember==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact group '%s' for service '%s' on host '%s' escalation\n",group_name,se->description,se->host_name);
@@ -3707,14 +3707,14 @@
 #endif
 		return NULL;
 	        }
-	new_contactgroupsmember->group_name=strdup(group_name);
+	new_contactgroupsmember->group_name=mt_strdup(group_name);
 	if(new_contactgroupsmember->group_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact group '%s' name for service '%s' on host '%s' escalation\n",group_name,se->description,se->host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contactgroupsmember);
+		mt_free(new_contactgroupsmember);
 		return NULL;
 	        }
 
@@ -3821,7 +3821,7 @@
                 }
 
 	/* allocate memory for a new service dependency entry */
-	new_servicedependency=(servicedependency *)malloc(sizeof(servicedependency));
+	new_servicedependency=(servicedependency *)mt_malloc(sizeof(servicedependency));
 	if(new_servicedependency==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' dependency\n",dependent_service_description,dependent_host_name);
@@ -3830,50 +3830,50 @@
 #endif
 		return NULL;
 	        }
-	new_servicedependency->dependent_host_name=strdup(dependent_host_name);
+	new_servicedependency->dependent_host_name=mt_strdup(dependent_host_name);
 	if(new_servicedependency->dependent_host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' dependency\n",dependent_service_description,dependent_host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_servicedependency);
+		mt_free(new_servicedependency);
 		return NULL;
 	        }
-	new_servicedependency->dependent_service_description=strdup(dependent_service_description);
+	new_servicedependency->dependent_service_description=mt_strdup(dependent_service_description);
 	if(new_servicedependency->dependent_service_description==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' dependency\n",dependent_service_description,dependent_host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_servicedependency);
-		free(new_servicedependency->dependent_host_name);
+		mt_free(new_servicedependency);
+		mt_free(new_servicedependency->dependent_host_name);
 		return NULL;
 	        }
-	new_servicedependency->host_name=strdup(host_name);
+	new_servicedependency->host_name=mt_strdup(host_name);
 	if(new_servicedependency->host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' dependency\n",dependent_service_description,dependent_host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_servicedependency);
-		free(new_servicedependency->dependent_host_name);
-		free(new_servicedependency->dependent_service_description);
+		mt_free(new_servicedependency);
+		mt_free(new_servicedependency->dependent_host_name);
+		mt_free(new_servicedependency->dependent_service_description);
 		return NULL;
 	        }
-	new_servicedependency->service_description=strdup(service_description);
+	new_servicedependency->service_description=mt_strdup(service_description);
 	if(new_servicedependency->service_description==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' dependency\n",dependent_service_description,dependent_host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_servicedependency);
-		free(new_servicedependency->dependent_host_name);
-		free(new_servicedependency->dependent_service_description);
-		free(new_servicedependency->host_name);
+		mt_free(new_servicedependency);
+		mt_free(new_servicedependency->dependent_host_name);
+		mt_free(new_servicedependency->dependent_service_description);
+		mt_free(new_servicedependency->host_name);
 		return NULL;
 	        }
 
@@ -3899,11 +3899,11 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_servicedependency->host_name);
-		free(new_servicedependency->service_description);
-		free(new_servicedependency->dependent_host_name);
-		free(new_servicedependency->dependent_service_description);
-		free(new_servicedependency);
+		mt_free(new_servicedependency->host_name);
+		mt_free(new_servicedependency->service_description);
+		mt_free(new_servicedependency->dependent_host_name);
+		mt_free(new_servicedependency->dependent_service_description);
+		mt_free(new_servicedependency);
 		return NULL;
 	        }
 
@@ -4001,7 +4001,7 @@
 	        }
 
 	/* allocate memory for a new host dependency entry */
-	new_hostdependency=(hostdependency *)malloc(sizeof(hostdependency));
+	new_hostdependency=(hostdependency *)mt_malloc(sizeof(hostdependency));
 	if(new_hostdependency==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' dependency\n",dependent_host_name);
@@ -4010,25 +4010,25 @@
 #endif
 		return NULL;
 	        }
-	new_hostdependency->dependent_host_name=strdup(dependent_host_name);
+	new_hostdependency->dependent_host_name=mt_strdup(dependent_host_name);
 	if(new_hostdependency->dependent_host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' dependency\n",dependent_host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostdependency);
+		mt_free(new_hostdependency);
 		return NULL;
 	        }
-	new_hostdependency->host_name=strdup(host_name);
+	new_hostdependency->host_name=mt_strdup(host_name);
 	if(new_hostdependency->host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' dependency\n",dependent_host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostdependency);
-		free(new_hostdependency->dependent_host_name);
+		mt_free(new_hostdependency);
+		mt_free(new_hostdependency->dependent_host_name);
 		return NULL;
 	        }
 
@@ -4049,9 +4049,9 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostdependency->host_name);
-		free(new_hostdependency->dependent_host_name);
-		free(new_hostdependency);
+		mt_free(new_hostdependency->host_name);
+		mt_free(new_hostdependency->dependent_host_name);
+		mt_free(new_hostdependency);
 		return NULL;
 	        }
 
@@ -4123,7 +4123,7 @@
 	        }
 
 	/* allocate memory for a new host escalation entry */
-	new_hostescalation=malloc(sizeof(hostescalation));
+	new_hostescalation=mt_malloc(sizeof(hostescalation));
 	if(new_hostescalation==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' escalation\n",host_name);
@@ -4132,28 +4132,28 @@
 #endif
 		return NULL;
 	        }
-	new_hostescalation->host_name=strdup(host_name);
+	new_hostescalation->host_name=mt_strdup(host_name);
 	if(new_hostescalation->host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' escalation host name\n",host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostescalation);
+		mt_free(new_hostescalation);
 		return NULL;
 	        }
 	if(escalation_period==NULL)
 		new_hostescalation->escalation_period=NULL;
 	else{
-		new_hostescalation->escalation_period=strdup(escalation_period);
+		new_hostescalation->escalation_period=mt_strdup(escalation_period);
 		if(new_hostescalation->escalation_period==NULL){
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' escalation period\n",host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-			free(new_hostescalation->host_name);
-			free(new_hostescalation);
+			mt_free(new_hostescalation->host_name);
+			mt_free(new_hostescalation);
 			return NULL;
 		        }
 	        }
@@ -4176,9 +4176,9 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostescalation->host_name);
-		free(new_hostescalation->escalation_period);
-		free(new_hostescalation);
+		mt_free(new_hostescalation->host_name);
+		mt_free(new_hostescalation->escalation_period);
+		mt_free(new_hostescalation);
 		return NULL;
 	        }
 
@@ -4247,7 +4247,7 @@
 	        }
 
 	/* allocate memory for the contactgroups member */
-	new_contactgroupsmember=(contactgroupsmember *)malloc(sizeof(contactgroupsmember));
+	new_contactgroupsmember=(contactgroupsmember *)mt_malloc(sizeof(contactgroupsmember));
 	if(new_contactgroupsmember==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact group '%s' for host '%s' escalation\n",group_name,he->host_name);
@@ -4256,14 +4256,14 @@
 #endif
 		return NULL;
 	        }
-	new_contactgroupsmember->group_name=strdup(group_name);
+	new_contactgroupsmember->group_name=mt_strdup(group_name);
 	if(new_contactgroupsmember->group_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for contact group '%s' name for host '%s' escalation\n",group_name,he->host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_contactgroupsmember);
+		mt_free(new_contactgroupsmember);
 		return NULL;
 	        }
 
@@ -4303,7 +4303,7 @@
 	        }
 
 	/* allocate memory for a new data structure */
-	new_hostextinfo=(hostextinfo *)malloc(sizeof(hostextinfo));
+	new_hostextinfo=(hostextinfo *)mt_malloc(sizeof(hostextinfo));
 	if(new_hostextinfo==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' extended info.\n",host_name);
@@ -4313,24 +4313,24 @@
 		return NULL;
 	        }
 				
-	new_hostextinfo->host_name=strdup(host_name);
+	new_hostextinfo->host_name=mt_strdup(host_name);
 	if(new_hostextinfo->host_name==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' extended info.\n",host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostextinfo);
+		mt_free(new_hostextinfo);
 		return NULL;
 	        }
 
 	if(notes==NULL || !strcmp(notes,""))
 		new_hostextinfo->notes=NULL;
 	else{
-		new_hostextinfo->notes=strdup(notes);
+		new_hostextinfo->notes=mt_strdup(notes);
 		if(new_hostextinfo->notes==NULL){
-			free(new_hostextinfo->host_name);
-			free(new_hostextinfo);
+			mt_free(new_hostextinfo->host_name);
+			mt_free(new_hostextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' extended info.\n",host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4343,11 +4343,11 @@
 	if(notes_url==NULL || !strcmp(notes_url,""))
 		new_hostextinfo->notes_url=NULL;
 	else{
-		new_hostextinfo->notes_url=strdup(notes_url);
+		new_hostextinfo->notes_url=mt_strdup(notes_url);
 		if(new_hostextinfo->notes_url==NULL){
-			free(new_hostextinfo->notes);
-			free(new_hostextinfo->host_name);
-			free(new_hostextinfo);
+			mt_free(new_hostextinfo->notes);
+			mt_free(new_hostextinfo->host_name);
+			mt_free(new_hostextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' extended info.\n",host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4360,12 +4360,12 @@
 	if(action_url==NULL || !strcmp(action_url,""))
 		new_hostextinfo->action_url=NULL;
 	else{
-		new_hostextinfo->action_url=strdup(action_url);
+		new_hostextinfo->action_url=mt_strdup(action_url);
 		if(new_hostextinfo->action_url==NULL){
-			free(new_hostextinfo->notes_url);
-			free(new_hostextinfo->notes);
-			free(new_hostextinfo->host_name);
-			free(new_hostextinfo);
+			mt_free(new_hostextinfo->notes_url);
+			mt_free(new_hostextinfo->notes);
+			mt_free(new_hostextinfo->host_name);
+			mt_free(new_hostextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' extended info.\n",host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4378,13 +4378,13 @@
 	if(icon_image==NULL || !strcmp(icon_image,""))
 		new_hostextinfo->icon_image=NULL;
 	else{
-		new_hostextinfo->icon_image=strdup(icon_image);
+		new_hostextinfo->icon_image=mt_strdup(icon_image);
 		if(new_hostextinfo->icon_image==NULL){
-			free(new_hostextinfo->action_url);
-			free(new_hostextinfo->notes_url);
-			free(new_hostextinfo->notes);
-			free(new_hostextinfo->host_name);
-			free(new_hostextinfo);
+			mt_free(new_hostextinfo->action_url);
+			mt_free(new_hostextinfo->notes_url);
+			mt_free(new_hostextinfo->notes);
+			mt_free(new_hostextinfo->host_name);
+			mt_free(new_hostextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' extended info.\n",host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4397,14 +4397,14 @@
 	if(vrml_image==NULL || !strcmp(vrml_image,""))
 		new_hostextinfo->vrml_image=NULL;
 	else{
-		new_hostextinfo->vrml_image=strdup(vrml_image);
+		new_hostextinfo->vrml_image=mt_strdup(vrml_image);
 		if(new_hostextinfo->vrml_image==NULL){
-			free(new_hostextinfo->icon_image);
-			free(new_hostextinfo->action_url);
-			free(new_hostextinfo->notes_url);
-			free(new_hostextinfo->notes);
-			free(new_hostextinfo->host_name);
-			free(new_hostextinfo);
+			mt_free(new_hostextinfo->icon_image);
+			mt_free(new_hostextinfo->action_url);
+			mt_free(new_hostextinfo->notes_url);
+			mt_free(new_hostextinfo->notes);
+			mt_free(new_hostextinfo->host_name);
+			mt_free(new_hostextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' extended info.\n",host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4418,15 +4418,15 @@
 	if(statusmap_image==NULL || !strcmp(statusmap_image,""))
 		new_hostextinfo->statusmap_image=NULL;
 	else{
-		new_hostextinfo->statusmap_image=strdup(statusmap_image);
+		new_hostextinfo->statusmap_image=mt_strdup(statusmap_image);
 		if(new_hostextinfo->statusmap_image==NULL){
-			free(new_hostextinfo->vrml_image);
-			free(new_hostextinfo->icon_image);
-			free(new_hostextinfo->action_url);
-			free(new_hostextinfo->notes_url);
-			free(new_hostextinfo->notes);
-			free(new_hostextinfo->host_name);
-			free(new_hostextinfo);
+			mt_free(new_hostextinfo->vrml_image);
+			mt_free(new_hostextinfo->icon_image);
+			mt_free(new_hostextinfo->action_url);
+			mt_free(new_hostextinfo->notes_url);
+			mt_free(new_hostextinfo->notes);
+			mt_free(new_hostextinfo->host_name);
+			mt_free(new_hostextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' extended info.\n",host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4440,16 +4440,16 @@
 	if(icon_image_alt==NULL || !strcmp(icon_image_alt,""))
 		new_hostextinfo->icon_image_alt=NULL;
 	else{
-		new_hostextinfo->icon_image_alt=strdup(icon_image_alt);
+		new_hostextinfo->icon_image_alt=mt_strdup(icon_image_alt);
 		if(new_hostextinfo->icon_image_alt==NULL){
-			free(new_hostextinfo->statusmap_image);
-			free(new_hostextinfo->vrml_image);
-			free(new_hostextinfo->icon_image);
-			free(new_hostextinfo->action_url);
-			free(new_hostextinfo->notes_url);
-			free(new_hostextinfo->notes);
-			free(new_hostextinfo->host_name);
-			free(new_hostextinfo);
+			mt_free(new_hostextinfo->statusmap_image);
+			mt_free(new_hostextinfo->vrml_image);
+			mt_free(new_hostextinfo->icon_image);
+			mt_free(new_hostextinfo->action_url);
+			mt_free(new_hostextinfo->notes_url);
+			mt_free(new_hostextinfo->notes);
+			mt_free(new_hostextinfo->host_name);
+			mt_free(new_hostextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' extended info.\n",host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4483,15 +4483,15 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_hostextinfo->statusmap_image);
-		free(new_hostextinfo->vrml_image);
-		free(new_hostextinfo->icon_image);
-		free(new_hostextinfo->icon_image_alt);
-		free(new_hostextinfo->action_url);
-		free(new_hostextinfo->notes_url);
-		free(new_hostextinfo->notes);
-		free(new_hostextinfo->host_name);
-		free(new_hostextinfo);
+		mt_free(new_hostextinfo->statusmap_image);
+		mt_free(new_hostextinfo->vrml_image);
+		mt_free(new_hostextinfo->icon_image);
+		mt_free(new_hostextinfo->icon_image_alt);
+		mt_free(new_hostextinfo->action_url);
+		mt_free(new_hostextinfo->notes_url);
+		mt_free(new_hostextinfo->notes);
+		mt_free(new_hostextinfo->host_name);
+		mt_free(new_hostextinfo);
 		return NULL;
 	        }
 
@@ -4541,7 +4541,7 @@
 	        }
 
 	/* allocate memory for a new data structure */
-	new_serviceextinfo=(serviceextinfo *)malloc(sizeof(serviceextinfo));
+	new_serviceextinfo=(serviceextinfo *)mt_malloc(sizeof(serviceextinfo));
 	if(new_serviceextinfo==NULL){
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' extended info.\n",description,host_name);
@@ -4551,9 +4551,9 @@
 		return NULL;
 	        }
 				
-	new_serviceextinfo->host_name=strdup(host_name);
+	new_serviceextinfo->host_name=mt_strdup(host_name);
 	if(new_serviceextinfo->host_name==NULL){
-		free(new_serviceextinfo);
+		mt_free(new_serviceextinfo);
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' extended info.\n",description,host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4562,10 +4562,10 @@
 		return NULL;
 	        }
 				
-	new_serviceextinfo->description=strdup(description);
+	new_serviceextinfo->description=mt_strdup(description);
 	if(new_serviceextinfo->description==NULL){
-		free(new_serviceextinfo->host_name);
-		free(new_serviceextinfo);
+		mt_free(new_serviceextinfo->host_name);
+		mt_free(new_serviceextinfo);
 #ifdef NSCORE
 		snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' extended info.\n",description,host_name);
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4577,11 +4577,11 @@
 	if(notes==NULL || !strcmp(notes,""))
 		new_serviceextinfo->notes=NULL;
 	else{
-		new_serviceextinfo->notes=strdup(notes);
+		new_serviceextinfo->notes=mt_strdup(notes);
 		if(new_serviceextinfo->notes==NULL){
-			free(new_serviceextinfo->description);
-			free(new_serviceextinfo->host_name);
-			free(new_serviceextinfo);
+			mt_free(new_serviceextinfo->description);
+			mt_free(new_serviceextinfo->host_name);
+			mt_free(new_serviceextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' extended info.\n",description,host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4594,12 +4594,12 @@
 	if(notes_url==NULL || !strcmp(notes_url,""))
 		new_serviceextinfo->notes_url=NULL;
 	else{
-		new_serviceextinfo->notes_url=strdup(notes_url);
+		new_serviceextinfo->notes_url=mt_strdup(notes_url);
 		if(new_serviceextinfo->notes_url==NULL){
-			free(new_serviceextinfo->notes);
-			free(new_serviceextinfo->description);
-			free(new_serviceextinfo->host_name);
-			free(new_serviceextinfo);
+			mt_free(new_serviceextinfo->notes);
+			mt_free(new_serviceextinfo->description);
+			mt_free(new_serviceextinfo->host_name);
+			mt_free(new_serviceextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' extended info.\n",description,host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4612,13 +4612,13 @@
 	if(action_url==NULL || !strcmp(action_url,""))
 		new_serviceextinfo->action_url=NULL;
 	else{
-		new_serviceextinfo->action_url=strdup(action_url);
+		new_serviceextinfo->action_url=mt_strdup(action_url);
 		if(new_serviceextinfo->action_url==NULL){
-			free(new_serviceextinfo->notes_url);
-			free(new_serviceextinfo->notes);
-			free(new_serviceextinfo->description);
-			free(new_serviceextinfo->host_name);
-			free(new_serviceextinfo);
+			mt_free(new_serviceextinfo->notes_url);
+			mt_free(new_serviceextinfo->notes);
+			mt_free(new_serviceextinfo->description);
+			mt_free(new_serviceextinfo->host_name);
+			mt_free(new_serviceextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' extended info.\n",description,host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4631,14 +4631,14 @@
 	if(icon_image==NULL || !strcmp(icon_image,""))
 		new_serviceextinfo->icon_image=NULL;
 	else{
-		new_serviceextinfo->icon_image=strdup(icon_image);
+		new_serviceextinfo->icon_image=mt_strdup(icon_image);
 		if(new_serviceextinfo->icon_image==NULL){
-			free(new_serviceextinfo->notes);
-			free(new_serviceextinfo->notes_url);
-			free(new_serviceextinfo->action_url);
-			free(new_serviceextinfo->description);
-			free(new_serviceextinfo->host_name);
-			free(new_serviceextinfo);
+			mt_free(new_serviceextinfo->notes);
+			mt_free(new_serviceextinfo->notes_url);
+			mt_free(new_serviceextinfo->action_url);
+			mt_free(new_serviceextinfo->description);
+			mt_free(new_serviceextinfo->host_name);
+			mt_free(new_serviceextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' extended info.\n",description,host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4651,15 +4651,15 @@
 	if(icon_image_alt==NULL || !strcmp(icon_image_alt,""))
 		new_serviceextinfo->icon_image_alt=NULL;
 	else{
-		new_serviceextinfo->icon_image_alt=strdup(icon_image_alt);
+		new_serviceextinfo->icon_image_alt=mt_strdup(icon_image_alt);
 		if(new_serviceextinfo->icon_image_alt==NULL){
-			free(new_serviceextinfo->icon_image);
-			free(new_serviceextinfo->notes);
-			free(new_serviceextinfo->notes_url);
-			free(new_serviceextinfo->action_url);
-			free(new_serviceextinfo->description);
-			free(new_serviceextinfo->host_name);
-			free(new_serviceextinfo);
+			mt_free(new_serviceextinfo->icon_image);
+			mt_free(new_serviceextinfo->notes);
+			mt_free(new_serviceextinfo->notes_url);
+			mt_free(new_serviceextinfo->action_url);
+			mt_free(new_serviceextinfo->description);
+			mt_free(new_serviceextinfo->host_name);
+			mt_free(new_serviceextinfo);
 #ifdef NSCORE
 			snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' extended info.\n",description,host_name);
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
@@ -4679,14 +4679,14 @@
 		temp_buffer[sizeof(temp_buffer)-1]='\x0';
 		write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-		free(new_serviceextinfo->icon_image);
-		free(new_serviceextinfo->icon_image_alt);
-		free(new_serviceextinfo->notes_url);
-		free(new_serviceextinfo->notes);
-		free(new_serviceextinfo->action_url);
-		free(new_serviceextinfo->description);
-		free(new_serviceextinfo->host_name);
-		free(new_serviceextinfo);
+		mt_free(new_serviceextinfo->icon_image);
+		mt_free(new_serviceextinfo->icon_image_alt);
+		mt_free(new_serviceextinfo->notes_url);
+		mt_free(new_serviceextinfo->notes);
+		mt_free(new_serviceextinfo->action_url);
+		mt_free(new_serviceextinfo->description);
+		mt_free(new_serviceextinfo->host_name);
+		mt_free(new_serviceextinfo);
 		return NULL;
 	        }
 
@@ -5691,19 +5691,19 @@
 
 			for(this_timerange=this_timeperiod->days[day];this_timerange!=NULL;this_timerange=next_timerange){
 				next_timerange=this_timerange->next;
-				free(this_timerange);
+				mt_free(this_timerange);
 			        }
 		        }
 
 		next_timeperiod=this_timeperiod->next;
-		free(this_timeperiod->name);
-		free(this_timeperiod->alias);
-		free(this_timeperiod);
+		mt_free(this_timeperiod->name);
+		mt_free(this_timeperiod->alias);
+		mt_free(this_timeperiod);
 		this_timeperiod=next_timeperiod;
 		}
 
 	/* free hashlist and reset pointers */
-	free(timeperiod_hashlist);
+	mt_free(timeperiod_hashlist);
 	timeperiod_hashlist=NULL;
 	timeperiod_list=NULL;
 
@@ -5721,8 +5721,8 @@
 		this_hostsmember=this_host->parent_hosts;
 		while(this_hostsmember!=NULL){
 			next_hostsmember=this_hostsmember->next;
-			free(this_hostsmember->host_name);
-			free(this_hostsmember);
+			mt_free(this_hostsmember->host_name);
+			mt_free(this_hostsmember);
 			this_hostsmember=next_hostsmember;
 			}
 
@@ -5730,29 +5730,29 @@
 		this_contactgroupsmember=this_host->contact_groups;
 		while(this_contactgroupsmember!=NULL){
 			next_contactgroupsmember=this_contactgroupsmember->next;
-			free(this_contactgroupsmember->group_name);
-			free(this_contactgroupsmember);
+			mt_free(this_contactgroupsmember->group_name);
+			mt_free(this_contactgroupsmember);
 			this_contactgroupsmember=next_contactgroupsmember;
 			}
 
-		free(this_host->name);
-		free(this_host->alias);
-		free(this_host->address);
+		mt_free(this_host->name);
+		mt_free(this_host->alias);
+		mt_free(this_host->address);
 
 #ifdef NSCORE
-		free(this_host->plugin_output);
-		free(this_host->perf_data);
-#endif
-		free(this_host->host_check_command);
-		free(this_host->event_handler);
-		free(this_host->failure_prediction_options);
-		free(this_host->notification_period);
-		free(this_host);
+		mt_free(this_host->plugin_output);
+		mt_free(this_host->perf_data);
+#endif
+		mt_free(this_host->host_check_command);
+		mt_free(this_host->event_handler);
+		mt_free(this_host->failure_prediction_options);
+		mt_free(this_host->notification_period);
+		mt_free(this_host);
 		this_host=next_host;
 	        }
 
 	/* free hashlist and reset pointers */
-	free(host_hashlist);
+	mt_free(host_hashlist);
 	host_hashlist=NULL;
 	host_list=NULL;
 
@@ -5768,20 +5768,20 @@
 		this_hostgroupmember=this_hostgroup->members;
 		while(this_hostgroupmember!=NULL){
 			next_hostgroupmember=this_hostgroupmember->next;
-			free(this_hostgroupmember->host_name);
-			free(this_hostgroupmember);
+			mt_free(this_hostgroupmember->host_name);
+			mt_free(this_hostgroupmember);
 			this_hostgroupmember=next_hostgroupmember;
 		        }
 
 		next_hostgroup=this_hostgroup->next;
-		free(this_hostgroup->group_name);
-		free(this_hostgroup->alias);
-		free(this_hostgroup);
+		mt_free(this_hostgroup->group_name);
+		mt_free(this_hostgroup->alias);
+		mt_free(this_hostgroup);
 		this_hostgroup=next_hostgroup;
 		}
 
 	/* free hashlist and reset pointers */
-	free(hostgroup_hashlist);
+	mt_free(hostgroup_hashlist);
 	hostgroup_hashlist=NULL;
 	hostgroup_list=NULL;
 
@@ -5797,21 +5797,21 @@
 		this_servicegroupmember=this_servicegroup->members;
 		while(this_servicegroupmember!=NULL){
 			next_servicegroupmember=this_servicegroupmember->next;
-			free(this_servicegroupmember->host_name);
-			free(this_servicegroupmember->service_description);
-			free(this_servicegroupmember);
+			mt_free(this_servicegroupmember->host_name);
+			mt_free(this_servicegroupmember->service_description);
+			mt_free(this_servicegroupmember);
 			this_servicegroupmember=next_servicegroupmember;
 		        }
 
 		next_servicegroup=this_servicegroup->next;
-		free(this_servicegroup->group_name);
-		free(this_servicegroup->alias);
-		free(this_servicegroup);
+		mt_free(this_servicegroup->group_name);
+		mt_free(this_servicegroup->alias);
+		mt_free(this_servicegroup);
 		this_servicegroup=next_servicegroup;
 		}
 
 	/* free hashlist and reset pointers */
-	free(servicegroup_hashlist);
+	mt_free(servicegroup_hashlist);
 	servicegroup_hashlist=NULL;
 	servicegroup_list=NULL;
 
@@ -5827,7 +5827,7 @@
 		this_commandsmember=this_contact->host_notification_commands;
 		while(this_commandsmember!=NULL){
 			next_commandsmember=this_commandsmember->next;
-			free(this_commandsmember);
+			mt_free(this_commandsmember);
 			this_commandsmember=next_commandsmember;
 		        }
 
@@ -5835,25 +5835,25 @@
 		this_commandsmember=this_contact->service_notification_commands;
 		while(this_commandsmember!=NULL){
 			next_commandsmember=this_commandsmember->next;
-			free(this_commandsmember);
+			mt_free(this_commandsmember);
 			this_commandsmember=next_commandsmember;
 		        }
 
 		next_contact=this_contact->next;
-		free(this_contact->name);
-		free(this_contact->alias);
-		free(this_contact->email);
-		free(this_contact->pager);
+		mt_free(this_contact->name);
+		mt_free(this_contact->alias);
+		mt_free(this_contact->email);
+		mt_free(this_contact->pager);
 		for(i=0;i<MAX_CONTACT_ADDRESSES;i++)
-			free(this_contact->address[i]);
-		free(this_contact->host_notification_period);
-		free(this_contact->service_notification_period);
-		free(this_contact);
+			mt_free(this_contact->address[i]);
+		mt_free(this_contact->host_notification_period);
+		mt_free(this_contact->service_notification_period);
+		mt_free(this_contact);
 		this_contact=next_contact;
 		}
 
 	/* free hashlist and reset pointers */
-	free(contact_hashlist);
+	mt_free(contact_hashlist);
 	contact_hashlist=NULL;
 	contact_list=NULL;
 
@@ -5869,20 +5869,20 @@
 		this_contactgroupmember=this_contactgroup->members;
 		while(this_contactgroupmember!=NULL){
 			next_contactgroupmember=this_contactgroupmember->next;
-			free(this_contactgroupmember->contact_name);
-			free(this_contactgroupmember);
+			mt_free(this_contactgroupmember->contact_name);
+			mt_free(this_contactgroupmember);
 			this_contactgroupmember=next_contactgroupmember;
 		        }
 
 		next_contactgroup=this_contactgroup->next;
-		free(this_contactgroup->group_name);
-		free(this_contactgroup->alias);
-		free(this_contactgroup);
+		mt_free(this_contactgroup->group_name);
+		mt_free(this_contactgroup->alias);
+		mt_free(this_contactgroup);
 		this_contactgroup=next_contactgroup;
 		}
 
 	/* free hashlist and reset pointers */
-	free(contactgroup_hashlist);
+	mt_free(contactgroup_hashlist);
 	contactgroup_hashlist=NULL;
 	contactgroup_list=NULL;
 
@@ -5900,28 +5900,28 @@
 		this_contactgroupsmember=this_service->contact_groups;
 		while(this_contactgroupsmember!=NULL){
 			next_contactgroupsmember=this_contactgroupsmember->next;
-			free(this_contactgroupsmember->group_name);
-			free(this_contactgroupsmember);
+			mt_free(this_contactgroupsmember->group_name);
+			mt_free(this_contactgroupsmember);
 			this_contactgroupsmember=next_contactgroupsmember;
 	                }
 
-		free(this_service->host_name);
-		free(this_service->description);
-		free(this_service->service_check_command);
-#ifdef NSCORE
-		free(this_service->plugin_output);
-		free(this_service->perf_data);
-#endif
-		free(this_service->notification_period);
-		free(this_service->check_period);
-		free(this_service->event_handler);
-		free(this_service->failure_prediction_options);
-		free(this_service);
+		mt_free(this_service->host_name);
+		mt_free(this_service->description);
+		mt_free(this_service->service_check_command);
+#ifdef NSCORE
+		mt_free(this_service->plugin_output);
+		mt_free(this_service->perf_data);
+#endif
+		mt_free(this_service->notification_period);
+		mt_free(this_service->check_period);
+		mt_free(this_service->event_handler);
+		mt_free(this_service->failure_prediction_options);
+		mt_free(this_service);
 		this_service=next_service;
 	        }
 
 	/* free hashlist and reset pointers */
-	free(service_hashlist);
+	mt_free(service_hashlist);
 	service_hashlist=NULL;
 	service_list=NULL;
 
@@ -5933,14 +5933,14 @@
 	this_command=command_list;
 	while(this_command!=NULL){
 		next_command=this_command->next;
-		free(this_command->name);
-		free(this_command->command_line);
-		free(this_command);
+		mt_free(this_command->name);
+		mt_free(this_command->command_line);
+		mt_free(this_command);
 		this_command=next_command;
 	        }
 
 	/* free hashlist and reset pointers */
-	free(command_hashlist);
+	mt_free(command_hashlist);
 	command_hashlist=NULL;
 	command_list=NULL;
 
@@ -5952,15 +5952,15 @@
 	this_serviceescalation=serviceescalation_list;
 	while(this_serviceescalation!=NULL){
 		next_serviceescalation=this_serviceescalation->next;
-		free(this_serviceescalation->host_name);
-		free(this_serviceescalation->description);
-		free(this_serviceescalation->escalation_period);
-		free(this_serviceescalation);
+		mt_free(this_serviceescalation->host_name);
+		mt_free(this_serviceescalation->description);
+		mt_free(this_serviceescalation->escalation_period);
+		mt_free(this_serviceescalation);
 		this_serviceescalation=next_serviceescalation;
 	        }
 
 	/* free hashlist and reset pointers */
-	free(serviceescalation_hashlist);
+	mt_free(serviceescalation_hashlist);
 	serviceescalation_hashlist=NULL;
 	serviceescalation_list=NULL;
 
@@ -5972,16 +5972,16 @@
 	this_servicedependency=servicedependency_list;
 	while(this_servicedependency!=NULL){
 		next_servicedependency=this_servicedependency->next;
-		free(this_servicedependency->dependent_host_name);
-		free(this_servicedependency->dependent_service_description);
-		free(this_servicedependency->host_name);
-		free(this_servicedependency->service_description);
-		free(this_servicedependency);
+		mt_free(this_servicedependency->dependent_host_name);
+		mt_free(this_servicedependency->dependent_service_description);
+		mt_free(this_servicedependency->host_name);
+		mt_free(this_servicedependency->service_description);
+		mt_free(this_servicedependency);
 		this_servicedependency=next_servicedependency;
 	        }
 
 	/* free hashlist and reset pointers */
-	free(servicedependency_hashlist);
+	mt_free(servicedependency_hashlist);
 	servicedependency_hashlist=NULL;
 	servicedependency_list=NULL;
 
@@ -5993,14 +5993,14 @@
 	this_hostdependency=hostdependency_list;
 	while(this_hostdependency!=NULL){
 		next_hostdependency=this_hostdependency->next;
-		free(this_hostdependency->dependent_host_name);
-		free(this_hostdependency->host_name);
-		free(this_hostdependency);
+		mt_free(this_hostdependency->dependent_host_name);
+		mt_free(this_hostdependency->host_name);
+		mt_free(this_hostdependency);
 		this_hostdependency=next_hostdependency;
 	        }
 
 	/* free hashlist and reset pointers */
-	free(hostdependency_hashlist);
+	mt_free(hostdependency_hashlist);
 	hostdependency_hashlist=NULL;
 	hostdependency_list=NULL;
 
@@ -6012,14 +6012,14 @@
 	this_hostescalation=hostescalation_list;
 	while(this_hostescalation!=NULL){
 		next_hostescalation=this_hostescalation->next;
-		free(this_hostescalation->host_name);
-		free(this_hostescalation->escalation_period);
-		free(this_hostescalation);
+		mt_free(this_hostescalation->host_name);
+		mt_free(this_hostescalation->escalation_period);
+		mt_free(this_hostescalation);
 		this_hostescalation=next_hostescalation;
 	        }
 
 	/* free hashlist and reset pointers */
-	free(hostescalation_hashlist);
+	mt_free(hostescalation_hashlist);
 	hostescalation_hashlist=NULL;
 	hostescalation_list=NULL;
 
@@ -6052,15 +6052,15 @@
 	/* free memory for the extended host info list */
 	for(this_hostextinfo=hostextinfo_list;this_hostextinfo!=NULL;this_hostextinfo=next_hostextinfo){
 		next_hostextinfo=this_hostextinfo->next;
-		free(this_hostextinfo->host_name);
-		free(this_hostextinfo->notes);
-		free(this_hostextinfo->notes_url);
-		free(this_hostextinfo->action_url);
-		free(this_hostextinfo->icon_image);
-		free(this_hostextinfo->vrml_image);
-		free(this_hostextinfo->statusmap_image);
-		free(this_hostextinfo->icon_image_alt);
-		free(this_hostextinfo);
+		mt_free(this_hostextinfo->host_name);
+		mt_free(this_hostextinfo->notes);
+		mt_free(this_hostextinfo->notes_url);
+		mt_free(this_hostextinfo->action_url);
+		mt_free(this_hostextinfo->icon_image);
+		mt_free(this_hostextinfo->vrml_image);
+		mt_free(this_hostextinfo->statusmap_image);
+		mt_free(this_hostextinfo->icon_image_alt);
+		mt_free(this_hostextinfo);
 	        }
 
 #ifdef DEBUG1
@@ -6068,21 +6068,21 @@
 #endif
 
 	/* free hashlist and reset pointers */
-	free(hostextinfo_hashlist);
+	mt_free(hostextinfo_hashlist);
 	hostextinfo_hashlist=NULL;
 	hostextinfo_list=NULL;
 
 	/* free memory for the extended service info list */
 	for(this_serviceextinfo=serviceextinfo_list;this_serviceextinfo!=NULL;this_serviceextinfo=next_serviceextinfo){
 		next_serviceextinfo=this_serviceextinfo->next;
-		free(this_serviceextinfo->host_name);
-		free(this_serviceextinfo->description);
-		free(this_serviceextinfo->notes);
-		free(this_serviceextinfo->notes_url);
-		free(this_serviceextinfo->action_url);
-		free(this_serviceextinfo->icon_image);
-		free(this_serviceextinfo->icon_image_alt);
-		free(this_serviceextinfo);
+		mt_free(this_serviceextinfo->host_name);
+		mt_free(this_serviceextinfo->description);
+		mt_free(this_serviceextinfo->notes);
+		mt_free(this_serviceextinfo->notes_url);
+		mt_free(this_serviceextinfo->action_url);
+		mt_free(this_serviceextinfo->icon_image);
+		mt_free(this_serviceextinfo->icon_image_alt);
+		mt_free(this_serviceextinfo);
 	        }
 
 #ifdef DEBUG1
@@ -6090,7 +6090,7 @@
 #endif
 
 	/* free hashlist and reset pointers */
-	free(serviceextinfo_hashlist);
+	mt_free(serviceextinfo_hashlist);
 	serviceextinfo_hashlist=NULL;
 	serviceextinfo_list=NULL;
 
diff -urN /home/exon/Nagios/common/snprintf.c ./common/snprintf.c
--- /home/exon/Nagios/common/snprintf.c	2004-11-05 15:18:47.000000000 +0100
+++ ./common/snprintf.c	2004-12-01 22:48:30.000000000 +0100
@@ -102,7 +102,7 @@
 
 /* free memory if the pointer is valid and zero the pointer */
 #ifndef SAFE_FREE
-#define SAFE_FREE(x) do { if ((x) != NULL) {free((x)); (x)=NULL;} } while(0)
+#define SAFE_FREE(x) do { if ((x) != NULL) {mt_free((x)); (x)=NULL;} } while(0)
 #endif
 
 #ifndef VA_COPY
@@ -811,7 +811,7 @@
 	ret = vsnprintf(NULL, 0, format, ap2);
 	if (ret <= 0) return ret;
 
-	(*ptr) = (char *)malloc(ret+1);
+	(*ptr) = (char *)mt_malloc(ret+1);
 	if (!*ptr) return -1;
 
 	VA_COPY(ap2, ap);
diff -urN /home/exon/Nagios/common/statusdata.c ./common/statusdata.c
--- /home/exon/Nagios/common/statusdata.c	2004-11-05 15:18:47.000000000 +0100
+++ ./common/statusdata.c	2004-12-01 22:48:30.000000000 +0100
@@ -220,7 +220,7 @@
 	if(hoststatus_hashlist==NULL){
 		int i;
 
-		hoststatus_hashlist=(hoststatus **)malloc(sizeof(hoststatus *)*HOSTSTATUS_HASHSLOTS);
+		hoststatus_hashlist=(hoststatus **)mt_malloc(sizeof(hoststatus *)*HOSTSTATUS_HASHSLOTS);
 		if(hoststatus_hashlist==NULL)
 			return 0;
 		
@@ -259,7 +259,7 @@
 	if(servicestatus_hashlist==NULL){
 		int i;
 
-		servicestatus_hashlist=(servicestatus **)malloc(sizeof(servicestatus *)*SERVICESTATUS_HASHSLOTS);
+		servicestatus_hashlist=(servicestatus **)mt_malloc(sizeof(servicestatus *)*SERVICESTATUS_HASHSLOTS);
 		if(servicestatus_hashlist==NULL)
 			return 0;
 		
@@ -326,15 +326,15 @@
 		        }
 		if(new_hoststatus->has_been_checked==FALSE){
 			new_hoststatus->status=HOST_PENDING;
-			free(new_hoststatus->plugin_output);
+			mt_free(new_hoststatus->plugin_output);
 			if(new_hoststatus->should_be_scheduled==TRUE){
 				get_time_string(&new_hoststatus->next_check,date_string,sizeof(date_string),LONG_DATE_TIME);
 				snprintf(temp_buffer,sizeof(temp_buffer)-1,"Host check scheduled for %s",date_string);
 				temp_buffer[sizeof(temp_buffer)-1]='\x0';
-				new_hoststatus->plugin_output=strdup(temp_buffer);
+				new_hoststatus->plugin_output=mt_strdup(temp_buffer);
 			        }
 			else
-				new_hoststatus->plugin_output=strdup("Host has not been checked yet");
+				new_hoststatus->plugin_output=mt_strdup("Host has not been checked yet");
 		        }
 	        }
 
@@ -392,15 +392,15 @@
 		        }
 		if(new_svcstatus->has_been_checked==FALSE){
 			new_svcstatus->status=SERVICE_PENDING;
-			free(new_svcstatus->plugin_output);
+			mt_free(new_svcstatus->plugin_output);
 			if(new_svcstatus->should_be_scheduled==TRUE){
 				get_time_string(&new_svcstatus->next_check,date_string,sizeof(date_string),LONG_DATE_TIME);
 				snprintf(temp_buffer,sizeof(temp_buffer)-1,"Service check scheduled for %s",date_string);
 				temp_buffer[sizeof(temp_buffer)-1]='\x0';
-				new_svcstatus->plugin_output=strdup(temp_buffer);
+				new_svcstatus->plugin_output=mt_strdup(temp_buffer);
 			        }
 			else
-				new_svcstatus->plugin_output=strdup("Service is not scheduled to be checked...");
+				new_svcstatus->plugin_output=mt_strdup("Service is not scheduled to be checked...");
 		        }
 	        }
 
@@ -443,25 +443,25 @@
 	/* free memory for the host status list */
 	for(this_hoststatus=hoststatus_list;this_hoststatus!=NULL;this_hoststatus=next_hoststatus){
 		next_hoststatus=this_hoststatus->next;
-		free(this_hoststatus->host_name);
-		free(this_hoststatus->plugin_output);
-		free(this_hoststatus->perf_data);
-		free(this_hoststatus);
+		mt_free(this_hoststatus->host_name);
+		mt_free(this_hoststatus->plugin_output);
+		mt_free(this_hoststatus->perf_data);
+		mt_free(this_hoststatus);
 	        }
 
 	/* free memory for the service status list */
 	for(this_svcstatus=servicestatus_list;this_svcstatus!=NULL;this_svcstatus=next_svcstatus){
 		next_svcstatus=this_svcstatus->next;
-		free(this_svcstatus->host_name);
-		free(this_svcstatus->description);
-		free(this_svcstatus->plugin_output);
-		free(this_svcstatus->perf_data);
-		free(this_svcstatus);
+		mt_free(this_svcstatus->host_name);
+		mt_free(this_svcstatus->description);
+		mt_free(this_svcstatus->plugin_output);
+		mt_free(this_svcstatus->perf_data);
+		mt_free(this_svcstatus);
 	        }
 
 	/* free hash lists reset list pointers */
-	free(hoststatus_hashlist);
-	free(servicestatus_hashlist);
+	mt_free(hoststatus_hashlist);
+	mt_free(servicestatus_hashlist);
 	hoststatus_hashlist=NULL;
 	servicestatus_hashlist=NULL;
 	hoststatus_list=NULL;
diff -urN /home/exon/Nagios/include/memleak.h ./include/memleak.h
--- /home/exon/Nagios/include/memleak.h	1970-01-01 01:00:00.000000000 +0100
+++ ./include/memleak.h	2004-12-01 22:47:56.000000000 +0100
@@ -0,0 +1,34 @@
+/*
+ * $Id: $
+ *
+ * Header file for rudimentary garbage collector
+ *
+ */
+
+/* if we're not debugging for leaks, provide macros to the real functions */
+#ifndef MEMLEAK_DEBUG
+
+# define my_malloc(len) malloc(len)
+# define my_realloc(ptr, len) realloc(ptr, len)
+# define my_strdup(ptr) strdup(ptr)
+# define my_free(ptr) free(ptr)
+
+# define MALLOC(len) malloc(len)
+# define REALLOC(ptr, len) realloc(ptr, len)
+# define STRDUP(ptr) strdup(ptr)
+# define FREE(ptr) free(ptr)
+
+#else
+
+# include <stdlib.h>
+
+void *mt_malloc(size_t);
+void *mt_realloc(void *, size_t);
+char *mt_strdup(const char *);
+void mt_free(void *);
+# define MALLOC(len) mt_malloc(len)
+# define REALLOC(ptr, len) mt_realloc(ptr, len)
+# define STRDUP(ptr) mt_strdup(ptr)
+# define FREE(ptr) mt_free(ptr)
+
+#endif
diff -urN /home/exon/Nagios/include/nagios.h.in ./include/nagios.h.in
--- /home/exon/Nagios/include/nagios.h.in	2004-11-15 09:28:06.000000000 +0100
+++ ./include/nagios.h.in	2004-12-01 22:25:24.000000000 +0100
@@ -29,6 +29,8 @@
 #include "../include/config.h"
 #include "../include/objects.h"
 
+#include "../include/memleak.h"
+
 #ifdef HAVE_SYSLOG_H
 #include <syslog.h>
 #endif
diff -urN /home/exon/Nagios/leak_debug.sh ./leak_debug.sh
--- /home/exon/Nagios/leak_debug.sh	1970-01-01 01:00:00.000000000 +0100
+++ ./leak_debug.sh	2004-12-01 22:55:04.000000000 +0100
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+cc='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_'
+
+# this requires some manual fixing, but only when the pointer being free()'d
+# is typecast (usually to (void *) inside the parentheses
+#sed 's#\([^_]\)free(\([^)]*\)#\1mt_free(\2, "\2")#' $1
+#sed "s#\([$cc]*\)=malloc(\([^)]\))#\1=mt_malloc(\2, \"\1 : \2\")#" $1
+
+
+for i in "$@"; do
+
+	test "$i" = 'memleak.c' && continue
+
+	mv $i $i.bak
+
+	sed -e 's#\([^_g]\)free(#\1mt_free(#g' \
+		-e 's#\([=)]\)malloc(#\1mt_malloc(#g' \
+		-e 's#\([=)]\)realloc(#\1mt_realloc(#g' \
+		-e 's#\([=)]\)strdup(#\1mt_strdup(#g' \
+			$i.bak > $i
+done
diff -urN /home/exon/Nagios/xdata/xcddefault.c ./xdata/xcddefault.c
--- /home/exon/Nagios/xdata/xcddefault.c	2004-11-05 15:18:52.000000000 +0100
+++ ./xdata/xcddefault.c	2004-12-01 22:48:42.000000000 +0100
@@ -85,7 +85,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 		
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -113,7 +113,7 @@
 			while(1){
 
 				/* free memory */
-				free(input2);
+				mt_free(input2);
 
 				/* read the next line */
 				if((input2=mmap_fgets(thefile2))==NULL)
@@ -129,7 +129,7 @@
 			        }
 
 			/* free memory and close the file */
-			free(input2);
+			mt_free(input2);
 			mmap_fclose(thefile2);
 		        }
 #endif
@@ -141,7 +141,7 @@
 	        }
 
 	/* free memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	/* we didn't find the comment file */
@@ -155,8 +155,8 @@
 #ifdef NSCORE
 	/* save the comment data file macro */
 	if(macro_x[MACRO_COMMENTDATAFILE]!=NULL)
-		free(macro_x[MACRO_COMMENTDATAFILE]);
-	macro_x[MACRO_COMMENTDATAFILE]=(char *)strdup(xcddefault_comment_file);
+		mt_free(macro_x[MACRO_COMMENTDATAFILE]);
+	macro_x[MACRO_COMMENTDATAFILE]=(char *)mt_strdup(xcddefault_comment_file);
 	if(macro_x[MACRO_COMMENTDATAFILE]!=NULL)
 		strip(macro_x[MACRO_COMMENTDATAFILE]);
 #endif
@@ -516,7 +516,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -554,10 +554,10 @@
 			data_type=XCDDEFAULT_NO_DATA;
 
 			/* free temp memory */
-			free(host_name);
-			free(service_description);
-			free(author);
-			free(comment_data);
+			mt_free(host_name);
+			mt_free(service_description);
+			mt_free(author);
+			mt_free(comment_data);
 
 			/* reset defaults */
 			host_name=NULL;
@@ -588,9 +588,9 @@
 			case XCDDEFAULT_HOST_DATA:
 			case XCDDEFAULT_SERVICE_DATA:
 				if(!strcmp(var,"host_name"))
-					host_name=strdup(val);
+					host_name=mt_strdup(val);
 				else if(!strcmp(var,"service_description"))
-					service_description=strdup(val);
+					service_description=mt_strdup(val);
 				else if(!strcmp(var,"entry_type"))
 					entry_type=atoi(val);
 				else if(!strcmp(var,"comment_id"))
@@ -606,9 +606,9 @@
 				else if(!strcmp(var,"expire_time"))
 					expire_time=strtoul(val,NULL,10);
 				else if(!strcmp(var,"author"))
-					author=strdup(val);
+					author=mt_strdup(val);
 				else if(!strcmp(var,"comment_data"))
-					comment_data=strdup(val);
+					comment_data=mt_strdup(val);
 				break;
 
 			default:
@@ -619,7 +619,7 @@
 	        }
 
 	/* free memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	return OK;
diff -urN /home/exon/Nagios/xdata/xdddefault.c ./xdata/xdddefault.c
--- /home/exon/Nagios/xdata/xdddefault.c	2004-11-05 15:19:42.000000000 +0100
+++ ./xdata/xdddefault.c	2004-12-01 22:48:42.000000000 +0100
@@ -88,7 +88,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -116,7 +116,7 @@
 			while(1){
 
 				/* free memory */
-				free(input2);
+				mt_free(input2);
 
 				/* read the next line */
 				if((input2=mmap_fgets(thefile2))==NULL)
@@ -156,8 +156,8 @@
 #ifdef NSCORE
 	/* save the downtime data file macro */
 	if(macro_x[MACRO_DOWNTIMEDATAFILE]!=NULL)
-		free(macro_x[MACRO_DOWNTIMEDATAFILE]);
-	macro_x[MACRO_DOWNTIMEDATAFILE]=(char *)strdup(xdddefault_downtime_file);
+		mt_free(macro_x[MACRO_DOWNTIMEDATAFILE]);
+	macro_x[MACRO_DOWNTIMEDATAFILE]=(char *)mt_strdup(xdddefault_downtime_file);
 	if(macro_x[MACRO_DOWNTIMEDATAFILE]!=NULL)
 		strip(macro_x[MACRO_DOWNTIMEDATAFILE]);
 #endif
@@ -526,7 +526,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* get the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -573,10 +573,10 @@
 			data_type=XDDDEFAULT_NO_DATA;
 
 			/* free temp memory */
-			free(host_name);
-			free(service_description);
-			free(author);
-			free(comment);
+			mt_free(host_name);
+			mt_free(service_description);
+			mt_free(author);
+			mt_free(comment);
 
 			/* reset defaults */
 			host_name=NULL;
@@ -607,9 +607,9 @@
 			case XDDDEFAULT_HOST_DATA:
 			case XDDDEFAULT_SERVICE_DATA:
 				if(!strcmp(var,"host_name"))
-					host_name=strdup(val);
+					host_name=mt_strdup(val);
 				else if(!strcmp(var,"service_description"))
-					service_description=strdup(val);
+					service_description=mt_strdup(val);
 				else if(!strcmp(var,"downtime_id"))
 					downtime_id=strtoul(val,NULL,10);
 				else if(!strcmp(var,"entry_time"))
@@ -625,9 +625,9 @@
 				else if(!strcmp(var,"duration"))
 					duration=strtoul(val,NULL,10);
 				else if(!strcmp(var,"author"))
-					author=strdup(val);
+					author=mt_strdup(val);
 				else if(!strcmp(var,"comment"))
-					comment=strdup(val);
+					comment=mt_strdup(val);
 				break;
 
 			default:
@@ -638,7 +638,7 @@
 	        }
 
 	/* free memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	return OK;
diff -urN /home/exon/Nagios/xdata/xodtemplate.c ./xdata/xodtemplate.c
--- /home/exon/Nagios/xdata/xodtemplate.c	2004-12-01 20:16:03.000000000 +0100
+++ ./xdata/xodtemplate.c	2004-12-01 22:55:25.000000000 +0100
@@ -150,7 +150,7 @@
 
 	/* allocate memory for 256 config files (increased dynamically) */
 	xodtemplate_current_config_file=0;
-	xodtemplate_config_files=(char **)malloc(256*sizeof(char **));
+	xodtemplate_config_files=(char **)mt_malloc(256*sizeof(char **));
 	if(xodtemplate_config_files==NULL){
 #ifdef DEBUG1
 		printf("Error: Cannot allocate memory for config file names!\n");
@@ -165,7 +165,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* get the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -226,7 +226,7 @@
 	        }
 
 	/* free memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 #endif
 
@@ -299,7 +299,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -335,8 +335,8 @@
 #ifdef NSCORE
 	/* save the object cache file macro */
 	if(macro_x[MACRO_OBJECTCACHEFILE]!=NULL)
-		free(macro_x[MACRO_OBJECTCACHEFILE]);
-	macro_x[MACRO_OBJECTCACHEFILE]=(char *)strdup(xodtemplate_cache_file);
+		mt_free(macro_x[MACRO_OBJECTCACHEFILE]);
+	macro_x[MACRO_OBJECTCACHEFILE]=(char *)mt_strdup(xodtemplate_cache_file);
 	if(macro_x[MACRO_OBJECTCACHEFILE]!=NULL)
 		strip(macro_x[MACRO_OBJECTCACHEFILE]);
 #endif
@@ -557,11 +557,11 @@
 
 
 	/* save config file name */
-	xodtemplate_config_files[xodtemplate_current_config_file++]=strdup(filename);
+	xodtemplate_config_files[xodtemplate_current_config_file++]=mt_strdup(filename);
 
 	/* reallocate memory for config files */
 	if(!(xodtemplate_current_config_file%256)){
-		xodtemplate_config_files=(char **)realloc(xodtemplate_config_files,(xodtemplate_current_config_file+256)*sizeof(char **));
+		xodtemplate_config_files=(char **)mt_realloc(xodtemplate_config_files,(xodtemplate_current_config_file+256)*sizeof(char **));
 		if(xodtemplate_config_files==NULL){
 #ifdef DEBUG1
 			printf("Error: Cannot re-allocate memory for config file names!\n");
@@ -584,7 +584,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -763,7 +763,7 @@
 	        }
 
 	/* free memory and close file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	/* whoops - EOF while we were in the middle of an object definition... */
@@ -917,7 +917,7 @@
 	case XODTEMPLATE_TIMEPERIOD:
 
 		/* allocate memory */
-		new_timeperiod=(xodtemplate_timeperiod *)malloc(sizeof(xodtemplate_timeperiod));
+		new_timeperiod=(xodtemplate_timeperiod *)mt_malloc(sizeof(xodtemplate_timeperiod));
 		if(new_timeperiod==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for timeperiod definition\n");
@@ -948,7 +948,7 @@
 	case XODTEMPLATE_COMMAND:
 
 		/* allocate memory */
-		new_command=(xodtemplate_command *)malloc(sizeof(xodtemplate_command));
+		new_command=(xodtemplate_command *)mt_malloc(sizeof(xodtemplate_command));
 		if(new_command==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for command definition\n");
@@ -977,7 +977,7 @@
 	case XODTEMPLATE_CONTACTGROUP:
 
 		/* allocate memory */
-		new_contactgroup=(xodtemplate_contactgroup *)malloc(sizeof(xodtemplate_contactgroup));
+		new_contactgroup=(xodtemplate_contactgroup *)mt_malloc(sizeof(xodtemplate_contactgroup));
 		if(new_contactgroup==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for contactgroup definition\n");
@@ -1007,7 +1007,7 @@
 	case XODTEMPLATE_HOSTGROUP:
 
 		/* allocate memory */
-		new_hostgroup=(xodtemplate_hostgroup *)malloc(sizeof(xodtemplate_hostgroup));
+		new_hostgroup=(xodtemplate_hostgroup *)mt_malloc(sizeof(xodtemplate_hostgroup));
 		if(new_hostgroup==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for hostgroup definition\n");
@@ -1036,7 +1036,7 @@
 	case XODTEMPLATE_SERVICEGROUP:
 
 		/* allocate memory */
-		new_servicegroup=(xodtemplate_servicegroup *)malloc(sizeof(xodtemplate_servicegroup));
+		new_servicegroup=(xodtemplate_servicegroup *)mt_malloc(sizeof(xodtemplate_servicegroup));
 		if(new_servicegroup==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for servicegroup definition\n");
@@ -1066,7 +1066,7 @@
 	case XODTEMPLATE_SERVICEDEPENDENCY:
 
 		/* allocate memory */
-		new_servicedependency=(xodtemplate_servicedependency *)malloc(sizeof(xodtemplate_servicedependency));
+		new_servicedependency=(xodtemplate_servicedependency *)mt_malloc(sizeof(xodtemplate_servicedependency));
 		if(new_servicedependency==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for servicedependency definition\n");
@@ -1114,7 +1114,7 @@
 	case XODTEMPLATE_SERVICEESCALATION:
 
 		/* allocate memory */
-		new_serviceescalation=(xodtemplate_serviceescalation *)malloc(sizeof(xodtemplate_serviceescalation));
+		new_serviceescalation=(xodtemplate_serviceescalation *)mt_malloc(sizeof(xodtemplate_serviceescalation));
 		if(new_serviceescalation==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for serviceescalation definition\n");
@@ -1157,7 +1157,7 @@
 	case XODTEMPLATE_CONTACT:
 
 		/* allocate memory */
-		new_contact=(xodtemplate_contact *)malloc(sizeof(xodtemplate_contact));
+		new_contact=(xodtemplate_contact *)mt_malloc(sizeof(xodtemplate_contact));
 		if(new_contact==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for contact definition\n");
@@ -1205,7 +1205,7 @@
 	case XODTEMPLATE_HOST:
 
 		/* allocate memory */
-		new_host=(xodtemplate_host *)malloc(sizeof(xodtemplate_host));
+		new_host=(xodtemplate_host *)mt_malloc(sizeof(xodtemplate_host));
 		if(new_host==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for host definition\n");
@@ -1286,7 +1286,7 @@
 	case XODTEMPLATE_SERVICE:
 
 		/* allocate memory */
-		new_service=(xodtemplate_service *)malloc(sizeof(xodtemplate_service));
+		new_service=(xodtemplate_service *)mt_malloc(sizeof(xodtemplate_service));
 		if(new_service==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for service definition\n");
@@ -1374,7 +1374,7 @@
 	case XODTEMPLATE_HOSTDEPENDENCY:
 
 		/* allocate memory */
-		new_hostdependency=(xodtemplate_hostdependency *)malloc(sizeof(xodtemplate_hostdependency));
+		new_hostdependency=(xodtemplate_hostdependency *)mt_malloc(sizeof(xodtemplate_hostdependency));
 		if(new_hostdependency==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for hostdependency definition\n");
@@ -1416,7 +1416,7 @@
 	case XODTEMPLATE_HOSTESCALATION:
 
 		/* allocate memory */
-		new_hostescalation=(xodtemplate_hostescalation *)malloc(sizeof(xodtemplate_hostescalation));
+		new_hostescalation=(xodtemplate_hostescalation *)mt_malloc(sizeof(xodtemplate_hostescalation));
 		if(new_hostescalation==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for hostescalation definition\n");
@@ -1456,7 +1456,7 @@
 	case XODTEMPLATE_HOSTEXTINFO:
 
 		/* allocate memory */
-		new_hostextinfo=(xodtemplate_hostextinfo *)malloc(sizeof(xodtemplate_hostextinfo));
+		new_hostextinfo=(xodtemplate_hostextinfo *)mt_malloc(sizeof(xodtemplate_hostextinfo));
 		if(new_hostextinfo==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for extended host info\n");
@@ -1498,7 +1498,7 @@
 	case XODTEMPLATE_SERVICEEXTINFO:
 
 		/* allocate memory */
-		new_serviceextinfo=(xodtemplate_serviceextinfo *)malloc(sizeof(xodtemplate_serviceextinfo));
+		new_serviceextinfo=(xodtemplate_serviceextinfo *)mt_malloc(sizeof(xodtemplate_serviceextinfo));
 		if(new_serviceextinfo==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for extended service info\n");
@@ -1686,7 +1686,7 @@
 		temp_timeperiod=(xodtemplate_timeperiod *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_timeperiod->template=strdup(value);
+			temp_timeperiod->template=mt_strdup(value);
 			if(temp_timeperiod->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for timeperiod template.\n");
@@ -1695,7 +1695,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_timeperiod->name=strdup(value);
+			temp_timeperiod->name=mt_strdup(value);
 			if(temp_timeperiod->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for timeperiod name.\n");
@@ -1704,7 +1704,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"timeperiod_name")){
-			temp_timeperiod->timeperiod_name=strdup(value);
+			temp_timeperiod->timeperiod_name=mt_strdup(value);
 			if(temp_timeperiod->timeperiod_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for timeperiod name.\n");
@@ -1713,7 +1713,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"alias")){
-			temp_timeperiod->alias=strdup(value);
+			temp_timeperiod->alias=mt_strdup(value);
 			if(temp_timeperiod->alias==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for timeperiod alias.\n");
@@ -1736,7 +1736,7 @@
 				x=6;
 			else
 				x=0;
-			temp_timeperiod->timeranges[x]=strdup(value);
+			temp_timeperiod->timeranges[x]=mt_strdup(value);
 			if(temp_timeperiod->timeranges[x]==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for timeperiod timerange.\n");
@@ -1763,7 +1763,7 @@
 		temp_command=(xodtemplate_command *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_command->template=strdup(value);
+			temp_command->template=mt_strdup(value);
 			if(temp_command->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for command template.\n");
@@ -1772,7 +1772,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_command->name=strdup(value);
+			temp_command->name=mt_strdup(value);
 			if(temp_command->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for command name.\n");
@@ -1781,7 +1781,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"command_name")){
-			temp_command->command_name=strdup(value);
+			temp_command->command_name=mt_strdup(value);
 			if(temp_command->command_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for command name.\n");
@@ -1790,7 +1790,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"command_line")){
-			temp_command->command_line=strdup(value);
+			temp_command->command_line=mt_strdup(value);
 			if(temp_command->command_line==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for command line.\n");
@@ -1816,7 +1816,7 @@
 		temp_contactgroup=(xodtemplate_contactgroup *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_contactgroup->template=strdup(value);
+			temp_contactgroup->template=mt_strdup(value);
 			if(temp_contactgroup->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contactgroup template.\n");
@@ -1825,7 +1825,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_contactgroup->name=strdup(value);
+			temp_contactgroup->name=mt_strdup(value);
 			if(temp_contactgroup->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contactgroup name.\n");
@@ -1834,7 +1834,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"contactgroup_name")){
-			temp_contactgroup->contactgroup_name=strdup(value);
+			temp_contactgroup->contactgroup_name=mt_strdup(value);
 			if(temp_contactgroup->contactgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contactgroup name.\n");
@@ -1843,7 +1843,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"alias")){
-			temp_contactgroup->alias=strdup(value);
+			temp_contactgroup->alias=mt_strdup(value);
 			if(temp_contactgroup->alias==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contactgroup alias.\n");
@@ -1852,7 +1852,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"members")){
-			temp_contactgroup->members=strdup(value);
+			temp_contactgroup->members=mt_strdup(value);
 			if(temp_contactgroup->members==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contactgroup members.\n");
@@ -1878,7 +1878,7 @@
 		temp_hostgroup=(xodtemplate_hostgroup *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_hostgroup->template=strdup(value);
+			temp_hostgroup->template=mt_strdup(value);
 			if(temp_hostgroup->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostgroup template.\n");
@@ -1887,7 +1887,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_hostgroup->name=strdup(value);
+			temp_hostgroup->name=mt_strdup(value);
 			if(temp_hostgroup->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostgroup name.\n");
@@ -1896,7 +1896,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"hostgroup_name")){
-			temp_hostgroup->hostgroup_name=strdup(value);
+			temp_hostgroup->hostgroup_name=mt_strdup(value);
 			if(temp_hostgroup->hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostgroup name.\n");
@@ -1905,7 +1905,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"alias")){
-			temp_hostgroup->alias=strdup(value);
+			temp_hostgroup->alias=mt_strdup(value);
 			if(temp_hostgroup->alias==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostgroup alias.\n");
@@ -1915,9 +1915,9 @@
 		        }
 		else if(!strcmp(variable,"members")){
 			if(temp_hostgroup->members==NULL)
-				temp_hostgroup->members=strdup(value);
+				temp_hostgroup->members=mt_strdup(value);
 			else{
-				temp_hostgroup->members=(char *)realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(value)+2);
+				temp_hostgroup->members=(char *)mt_realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(value)+2);
 				if(temp_hostgroup->members!=NULL){
 					strcat(temp_hostgroup->members,",");
 					strcat(temp_hostgroup->members,value);
@@ -1949,7 +1949,7 @@
 		temp_servicegroup=(xodtemplate_servicegroup *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_servicegroup->template=strdup(value);
+			temp_servicegroup->template=mt_strdup(value);
 			if(temp_servicegroup->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicegroup template.\n");
@@ -1958,7 +1958,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_servicegroup->name=strdup(value);
+			temp_servicegroup->name=mt_strdup(value);
 			if(temp_servicegroup->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicegroup name.\n");
@@ -1967,7 +1967,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"servicegroup_name")){
-			temp_servicegroup->servicegroup_name=strdup(value);
+			temp_servicegroup->servicegroup_name=mt_strdup(value);
 			if(temp_servicegroup->servicegroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicegroup name.\n");
@@ -1976,7 +1976,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"alias")){
-			temp_servicegroup->alias=strdup(value);
+			temp_servicegroup->alias=mt_strdup(value);
 			if(temp_servicegroup->alias==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicegroup alias.\n");
@@ -1986,9 +1986,9 @@
 		        }
 		else if(!strcmp(variable,"members")){
 			if(temp_servicegroup->members==NULL)
-				temp_servicegroup->members=strdup(value);
+				temp_servicegroup->members=mt_strdup(value);
 			else{
-				temp_servicegroup->members=(char *)realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(value)+2);
+				temp_servicegroup->members=(char *)mt_realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(value)+2);
 				if(temp_servicegroup->members!=NULL){
 					strcat(temp_servicegroup->members,",");
 					strcat(temp_servicegroup->members,value);
@@ -2020,7 +2020,7 @@
 		temp_servicedependency=(xodtemplate_servicedependency *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_servicedependency->template=strdup(value);
+			temp_servicedependency->template=mt_strdup(value);
 			if(temp_servicedependency->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency template.\n");
@@ -2029,7 +2029,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_servicedependency->name=strdup(value);
+			temp_servicedependency->name=mt_strdup(value);
 			if(temp_servicedependency->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency name.\n");
@@ -2038,7 +2038,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"servicegroup") || !strcmp(variable,"servicegroups") || !strcmp(variable,"servicegroup_name")){
-			temp_servicedependency->servicegroup_name=strdup(value);
+			temp_servicedependency->servicegroup_name=mt_strdup(value);
 			if(temp_servicedependency->servicegroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency servicegroup.\n");
@@ -2047,7 +2047,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
-			temp_servicedependency->hostgroup_name=strdup(value);
+			temp_servicedependency->hostgroup_name=mt_strdup(value);
 			if(temp_servicedependency->hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency hostgroup.\n");
@@ -2056,7 +2056,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host") || !strcmp(variable,"host_name") || !strcmp(variable,"master_host") || !strcmp(variable,"master_host_name")){
-			temp_servicedependency->host_name=strdup(value);
+			temp_servicedependency->host_name=mt_strdup(value);
 			if(temp_servicedependency->host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency host.\n");
@@ -2065,7 +2065,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"description") || !strcmp(variable,"service_description") || !strcmp(variable,"master_description") || !strcmp(variable,"master_service_description")){
-			temp_servicedependency->service_description=strdup(value);
+			temp_servicedependency->service_description=mt_strdup(value);
 			if(temp_servicedependency->service_description==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency service_description.\n");
@@ -2074,7 +2074,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"dependent_servicegroup") || !strcmp(variable,"dependent_servicegroups") || !strcmp(variable,"dependent_servicegroup_name")){
-			temp_servicedependency->dependent_servicegroup_name=strdup(value);
+			temp_servicedependency->dependent_servicegroup_name=mt_strdup(value);
 			if(temp_servicedependency->dependent_servicegroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency dependent servicegroup.\n");
@@ -2083,7 +2083,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"dependent_hostgroup") || !strcmp(variable,"dependent_hostgroups") || !strcmp(variable,"dependent_hostgroup_name")){
-			temp_servicedependency->dependent_hostgroup_name=strdup(value);
+			temp_servicedependency->dependent_hostgroup_name=mt_strdup(value);
 			if(temp_servicedependency->dependent_hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency dependent hostgroup.\n");
@@ -2092,7 +2092,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"dependent_host") || !strcmp(variable,"dependent_host_name")){
-			temp_servicedependency->dependent_host_name=strdup(value);
+			temp_servicedependency->dependent_host_name=mt_strdup(value);
 			if(temp_servicedependency->dependent_host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency dependent host.\n");
@@ -2101,7 +2101,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"dependent_description") || !strcmp(variable,"dependent_service_description")){
-			temp_servicedependency->dependent_service_description=strdup(value);
+			temp_servicedependency->dependent_service_description=mt_strdup(value);
 			if(temp_servicedependency->dependent_service_description==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for servicedependency dependent service_description.\n");
@@ -2192,7 +2192,7 @@
 		temp_serviceescalation=(xodtemplate_serviceescalation *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_serviceescalation->template=strdup(value);
+			temp_serviceescalation->template=mt_strdup(value);
 			if(temp_serviceescalation->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for serviceescalation template.\n");
@@ -2201,7 +2201,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_serviceescalation->name=strdup(value);
+			temp_serviceescalation->name=mt_strdup(value);
 			if(temp_serviceescalation->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for serviceescalation name.\n");
@@ -2210,7 +2210,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"servicegroup") || !strcmp(variable,"servicegroups") || !strcmp(variable,"servicegroup_name")){
-			temp_serviceescalation->servicegroup_name=strdup(value);
+			temp_serviceescalation->servicegroup_name=mt_strdup(value);
 			if(temp_serviceescalation->servicegroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for serviceescalation servicegroup.\n");
@@ -2219,7 +2219,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
-			temp_serviceescalation->hostgroup_name=strdup(value);
+			temp_serviceescalation->hostgroup_name=mt_strdup(value);
 			if(temp_serviceescalation->hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for serviceescalation hostgroup.\n");
@@ -2228,7 +2228,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host") || !strcmp(variable,"host_name")){
-			temp_serviceescalation->host_name=strdup(value);
+			temp_serviceescalation->host_name=mt_strdup(value);
 			if(temp_serviceescalation->host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for serviceescalation host.\n");
@@ -2237,7 +2237,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"description") || !strcmp(variable,"service_description")){
-			temp_serviceescalation->service_description=strdup(value);
+			temp_serviceescalation->service_description=mt_strdup(value);
 			if(temp_serviceescalation->service_description==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for serviceescalation service_description.\n");
@@ -2246,7 +2246,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"contact_groups")){
-			temp_serviceescalation->contact_groups=strdup(value);
+			temp_serviceescalation->contact_groups=mt_strdup(value);
 			if(temp_serviceescalation->contact_groups==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for serviceescalation contact_groups.\n");
@@ -2267,7 +2267,7 @@
 			temp_serviceescalation->have_notification_interval=TRUE;
 		        }
 		else if(!strcmp(variable,"escalation_period")){
-			temp_serviceescalation->escalation_period=strdup(value);
+			temp_serviceescalation->escalation_period=mt_strdup(value);
 			if(temp_serviceescalation->escalation_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for serviceescalation escalation_period.\n");
@@ -2321,7 +2321,7 @@
 		temp_contact=(xodtemplate_contact *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_contact->template=strdup(value);
+			temp_contact->template=mt_strdup(value);
 			if(temp_contact->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact template.\n");
@@ -2330,7 +2330,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_contact->name=strdup(value);
+			temp_contact->name=mt_strdup(value);
 			if(temp_contact->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact name.\n");
@@ -2339,7 +2339,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"contact_name")){
-			temp_contact->contact_name=strdup(value);
+			temp_contact->contact_name=mt_strdup(value);
 			if(temp_contact->contact_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact name.\n");
@@ -2348,7 +2348,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"alias")){
-			temp_contact->alias=strdup(value);
+			temp_contact->alias=mt_strdup(value);
 			if(temp_contact->alias==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact alias.\n");
@@ -2357,7 +2357,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"contactgroups")){
-			temp_contact->contactgroups=strdup(value);
+			temp_contact->contactgroups=mt_strdup(value);
 			if(temp_contact->contactgroups==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact contactgroups.\n");
@@ -2366,7 +2366,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"email")){
-			temp_contact->email=strdup(value);
+			temp_contact->email=mt_strdup(value);
 			if(temp_contact->email==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact email.\n");
@@ -2375,7 +2375,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"pager")){
-			temp_contact->pager=strdup(value);
+			temp_contact->pager=mt_strdup(value);
 			if(temp_contact->pager==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact pager.\n");
@@ -2391,7 +2391,7 @@
 #endif
 				return ERROR;
 			        }
-			temp_contact->address[x-1]=strdup(value);
+			temp_contact->address[x-1]=mt_strdup(value);
 			if(temp_contact->address[x-1]==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact address #%d.\n",x);
@@ -2400,7 +2400,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host_notification_period")){
-			temp_contact->host_notification_period=strdup(value);
+			temp_contact->host_notification_period=mt_strdup(value);
 			if(temp_contact->host_notification_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact host_notification_period.\n");
@@ -2409,7 +2409,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host_notification_commands")){
-			temp_contact->host_notification_commands=strdup(value);
+			temp_contact->host_notification_commands=mt_strdup(value);
 			if(temp_contact->host_notification_commands==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact host_notification_commands.\n");
@@ -2418,7 +2418,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"service_notification_period")){
-			temp_contact->service_notification_period=strdup(value);
+			temp_contact->service_notification_period=mt_strdup(value);
 			if(temp_contact->service_notification_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact service_notification_period.\n");
@@ -2427,7 +2427,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"service_notification_commands")){
-			temp_contact->service_notification_commands=strdup(value);
+			temp_contact->service_notification_commands=mt_strdup(value);
 			if(temp_contact->service_notification_commands==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact service_notification_commands.\n");
@@ -2436,7 +2436,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host_notification_period")){
-			temp_contact->host_notification_period=strdup(value);
+			temp_contact->host_notification_period=mt_strdup(value);
 			if(temp_contact->host_notification_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact host_notification_period.\n");
@@ -2445,7 +2445,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"service_notification_period")){
-			temp_contact->service_notification_period=strdup(value);
+			temp_contact->service_notification_period=mt_strdup(value);
 			if(temp_contact->service_notification_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for contact service_notification_period.\n");
@@ -2529,7 +2529,7 @@
 		temp_host=(xodtemplate_host *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_host->template=strdup(value);
+			temp_host->template=mt_strdup(value);
 			if(temp_host->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host template.\n");
@@ -2538,7 +2538,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_host->name=strdup(value);
+			temp_host->name=mt_strdup(value);
 			if(temp_host->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host name.\n");
@@ -2547,7 +2547,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host_name")){
-			temp_host->host_name=strdup(value);
+			temp_host->host_name=mt_strdup(value);
 			if(temp_host->host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host name.\n");
@@ -2556,7 +2556,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"alias")){
-			temp_host->alias=strdup(value);
+			temp_host->alias=mt_strdup(value);
 			if(temp_host->alias==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host alias.\n");
@@ -2565,7 +2565,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"address")){
-			temp_host->address=strdup(value);
+			temp_host->address=mt_strdup(value);
 			if(temp_host->address==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host address.\n");
@@ -2574,7 +2574,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"parents")){
-			temp_host->parents=strdup(value);
+			temp_host->parents=mt_strdup(value);
 			if(temp_host->parents==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host parents.\n");
@@ -2583,7 +2583,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"hostgroups")){
-			temp_host->hostgroups=strdup(value);
+			temp_host->hostgroups=mt_strdup(value);
 			if(temp_host->hostgroups==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host hostgroups.\n");
@@ -2592,7 +2592,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"contact_groups")){
-			temp_host->contact_groups=strdup(value);
+			temp_host->contact_groups=mt_strdup(value);
 			if(temp_host->contact_groups==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host contact_groups.\n");
@@ -2601,7 +2601,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"notification_period")){
-			temp_host->notification_period=strdup(value);
+			temp_host->notification_period=mt_strdup(value);
 			if(temp_host->notification_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host notification_period.\n");
@@ -2610,7 +2610,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"check_command")){
-			temp_host->check_command=strdup(value);
+			temp_host->check_command=mt_strdup(value);
 			if(temp_host->check_command==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host check_command.\n");
@@ -2619,7 +2619,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"check_period")){
-			temp_host->check_period=strdup(value);
+			temp_host->check_period=mt_strdup(value);
 			if(temp_host->check_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host check_period.\n");
@@ -2628,7 +2628,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"event_handler")){
-			temp_host->event_handler=strdup(value);
+			temp_host->event_handler=mt_strdup(value);
 			if(temp_host->event_handler==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host event_handler.\n");
@@ -2637,7 +2637,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"failure_prediction_options")){
-			temp_host->failure_prediction_options=strdup(value);
+			temp_host->failure_prediction_options=mt_strdup(value);
 			if(temp_host->failure_prediction_options==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for host failure_prediction_options.\n");
@@ -2782,7 +2782,7 @@
 		temp_service=(xodtemplate_service *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_service->template=strdup(value);
+			temp_service->template=mt_strdup(value);
 			if(temp_service->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service template.\n");
@@ -2791,7 +2791,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_service->name=strdup(value);
+			temp_service->name=mt_strdup(value);
 			if(temp_service->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service name.\n");
@@ -2800,7 +2800,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
-			temp_service->hostgroup_name=strdup(value);
+			temp_service->hostgroup_name=mt_strdup(value);
 			if(temp_service->hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service hostgroup.\n");
@@ -2809,7 +2809,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host") || !strcmp(variable,"hosts") || !strcmp(variable,"host_name")){
-			temp_service->host_name=strdup(value);
+			temp_service->host_name=mt_strdup(value);
 			if(temp_service->host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service host.\n");
@@ -2818,7 +2818,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"service_description") || !strcmp(variable,"description")){
-			temp_service->service_description=strdup(value);
+			temp_service->service_description=mt_strdup(value);
 			if(temp_service->service_description==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service service_description.\n");
@@ -2827,7 +2827,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"servicegroups")){
-			temp_service->servicegroups=strdup(value);
+			temp_service->servicegroups=mt_strdup(value);
 			if(temp_service->servicegroups==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service servicegroups.\n");
@@ -2836,7 +2836,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"check_command")){
-			temp_service->check_command=strdup(value);
+			temp_service->check_command=mt_strdup(value);
 			if(temp_service->check_command==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service check_command.\n");
@@ -2845,7 +2845,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"check_period")){
-			temp_service->check_period=strdup(value);
+			temp_service->check_period=mt_strdup(value);
 			if(temp_service->check_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service check_period.\n");
@@ -2854,7 +2854,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"event_handler")){
-			temp_service->event_handler=strdup(value);
+			temp_service->event_handler=mt_strdup(value);
 			if(temp_service->event_handler==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service event_handler.\n");
@@ -2863,7 +2863,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"notification_period")){
-			temp_service->notification_period=strdup(value);
+			temp_service->notification_period=mt_strdup(value);
 			if(temp_service->notification_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service notification_period.\n");
@@ -2872,7 +2872,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"contact_groups")){
-			temp_service->contact_groups=strdup(value);
+			temp_service->contact_groups=mt_strdup(value);
 			if(temp_service->contact_groups==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service contact_groups.\n");
@@ -2881,7 +2881,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"failure_prediction_options")){
-			temp_service->failure_prediction_options=strdup(value);
+			temp_service->failure_prediction_options=mt_strdup(value);
 			if(temp_service->failure_prediction_options==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for service failure_prediction_options.\n");
@@ -3044,7 +3044,7 @@
 		temp_hostdependency=(xodtemplate_hostdependency *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_hostdependency->template=strdup(value);
+			temp_hostdependency->template=mt_strdup(value);
 			if(temp_hostdependency->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostdependency template.\n");
@@ -3053,7 +3053,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_hostdependency->name=strdup(value);
+			temp_hostdependency->name=mt_strdup(value);
 			if(temp_hostdependency->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostdependency name.\n");
@@ -3062,7 +3062,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
-			temp_hostdependency->hostgroup_name=strdup(value);
+			temp_hostdependency->hostgroup_name=mt_strdup(value);
 			if(temp_hostdependency->hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostdependency hostgroup.\n");
@@ -3071,7 +3071,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host") || !strcmp(variable,"host_name") || !strcmp(variable,"master_host") || !strcmp(variable,"master_host_name")){
-			temp_hostdependency->host_name=strdup(value);
+			temp_hostdependency->host_name=mt_strdup(value);
 			if(temp_hostdependency->host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostdependency host.\n");
@@ -3080,7 +3080,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"dependent_hostgroup") || !strcmp(variable,"dependent_hostgroups") || !strcmp(variable,"dependent_hostgroup_name")){
-			temp_hostdependency->dependent_hostgroup_name=strdup(value);
+			temp_hostdependency->dependent_hostgroup_name=mt_strdup(value);
 			if(temp_hostdependency->dependent_hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostdependency dependent hostgroup.\n");
@@ -3089,7 +3089,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"dependent_host") || !strcmp(variable,"dependent_host_name")){
-			temp_hostdependency->dependent_host_name=strdup(value);
+			temp_hostdependency->dependent_host_name=mt_strdup(value);
 			if(temp_hostdependency->dependent_host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostdependency dependent host.\n");
@@ -3174,7 +3174,7 @@
 		temp_hostescalation=(xodtemplate_hostescalation *)xodtemplate_current_object;
 
 		if(!strcmp(variable,"use")){
-			temp_hostescalation->template=strdup(value);
+			temp_hostescalation->template=mt_strdup(value);
 			if(temp_hostescalation->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostescalation template.\n");
@@ -3183,7 +3183,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_hostescalation->name=strdup(value);
+			temp_hostescalation->name=mt_strdup(value);
 			if(temp_hostescalation->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostescalation name.\n");
@@ -3192,7 +3192,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroups") || !strcmp(variable,"hostgroup_name")){
-			temp_hostescalation->hostgroup_name=strdup(value);
+			temp_hostescalation->hostgroup_name=mt_strdup(value);
 			if(temp_hostescalation->hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostescalation hostgroup.\n");
@@ -3201,7 +3201,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host") || !strcmp(variable,"host_name")){
-			temp_hostescalation->host_name=strdup(value);
+			temp_hostescalation->host_name=mt_strdup(value);
 			if(temp_hostescalation->host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostescalation host.\n");
@@ -3210,7 +3210,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"contact_groups")){
-			temp_hostescalation->contact_groups=strdup(value);
+			temp_hostescalation->contact_groups=mt_strdup(value);
 			if(temp_hostescalation->contact_groups==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostescalation contact_groups.\n");
@@ -3231,7 +3231,7 @@
 			temp_hostescalation->have_notification_interval=TRUE;
 		        }
 		else if(!strcmp(variable,"escalation_period")){
-			temp_hostescalation->escalation_period=strdup(value);
+			temp_hostescalation->escalation_period=mt_strdup(value);
 			if(temp_hostescalation->escalation_period==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for hostescalation escalation_period.\n");
@@ -3281,7 +3281,7 @@
 		temp_hostextinfo=xodtemplate_hostextinfo_list;
 
 		if(!strcmp(variable,"use")){
-			temp_hostextinfo->template=strdup(value);
+			temp_hostextinfo->template=mt_strdup(value);
 			if(temp_hostextinfo->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info template.\n");
@@ -3290,7 +3290,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_hostextinfo->name=strdup(value);
+			temp_hostextinfo->name=mt_strdup(value);
 			if(temp_hostextinfo->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info name.\n");
@@ -3299,7 +3299,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host_name")){
-			temp_hostextinfo->host_name=(char *)malloc(strlen(value)+1);
+			temp_hostextinfo->host_name=(char *)mt_malloc(strlen(value)+1);
 			if(temp_hostextinfo->host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info host_name.\n");
@@ -3309,7 +3309,7 @@
 			strcpy(temp_hostextinfo->host_name,value);
 		        }
 		else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroup_name")){
-			temp_hostextinfo->hostgroup_name=strdup(value);
+			temp_hostextinfo->hostgroup_name=mt_strdup(value);
 			if(temp_hostextinfo->hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info hostgroup_name.\n");
@@ -3318,7 +3318,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"notes")){
-			temp_hostextinfo->notes=strdup(value);
+			temp_hostextinfo->notes=mt_strdup(value);
 			if(temp_hostextinfo->notes==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info notes.\n");
@@ -3327,7 +3327,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"notes_url")){
-			temp_hostextinfo->notes_url=strdup(value);
+			temp_hostextinfo->notes_url=mt_strdup(value);
 			if(temp_hostextinfo->notes_url==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info notes_url.\n");
@@ -3336,7 +3336,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"action_url")){
-			temp_hostextinfo->action_url=strdup(value);
+			temp_hostextinfo->action_url=mt_strdup(value);
 			if(temp_hostextinfo->action_url==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info action_url.\n");
@@ -3345,7 +3345,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"icon_image")){
-			temp_hostextinfo->icon_image=strdup(value);
+			temp_hostextinfo->icon_image=mt_strdup(value);
 			if(temp_hostextinfo->icon_image==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info icon_image.\n");
@@ -3354,7 +3354,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"icon_image_alt")){
-			temp_hostextinfo->icon_image_alt=strdup(value);
+			temp_hostextinfo->icon_image_alt=mt_strdup(value);
 			if(temp_hostextinfo->icon_image_alt==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info icon_image_alt.\n");
@@ -3363,7 +3363,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"vrml_image")){
-			temp_hostextinfo->vrml_image=strdup(value);
+			temp_hostextinfo->vrml_image=mt_strdup(value);
 			if(temp_hostextinfo->vrml_image==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info vrml_image.\n");
@@ -3372,7 +3372,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"gd2_image")|| !strcmp(variable,"statusmap_image")){
-			temp_hostextinfo->statusmap_image=strdup(value);
+			temp_hostextinfo->statusmap_image=mt_strdup(value);
 			if(temp_hostextinfo->statusmap_image==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended host info statusmap_image.\n");
@@ -3454,7 +3454,7 @@
 		temp_serviceextinfo=xodtemplate_serviceextinfo_list;
 
 		if(!strcmp(variable,"use")){
-			temp_serviceextinfo->template=strdup(value);
+			temp_serviceextinfo->template=mt_strdup(value);
 			if(temp_serviceextinfo->template==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info template.\n");
@@ -3463,7 +3463,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"name")){
-			temp_serviceextinfo->name=strdup(value);
+			temp_serviceextinfo->name=mt_strdup(value);
 			if(temp_serviceextinfo->name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info name.\n");
@@ -3472,7 +3472,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"host_name")){
-			temp_serviceextinfo->host_name=strdup(value);
+			temp_serviceextinfo->host_name=mt_strdup(value);
 			if(temp_serviceextinfo->host_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info host_name.\n");
@@ -3481,7 +3481,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"hostgroup") || !strcmp(variable,"hostgroup_name")){
-			temp_serviceextinfo->hostgroup_name=strdup(value);
+			temp_serviceextinfo->hostgroup_name=mt_strdup(value);
 			if(temp_serviceextinfo->hostgroup_name==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info hostgroup_name.\n");
@@ -3490,7 +3490,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"service_description")){
-			temp_serviceextinfo->service_description=strdup(value);
+			temp_serviceextinfo->service_description=mt_strdup(value);
 			if(temp_serviceextinfo->service_description==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info service_description.\n");
@@ -3499,7 +3499,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"notes")){
-			temp_serviceextinfo->notes=strdup(value);
+			temp_serviceextinfo->notes=mt_strdup(value);
 			if(temp_serviceextinfo->notes==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info notes.\n");
@@ -3508,7 +3508,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"notes_url")){
-			temp_serviceextinfo->notes_url=strdup(value);
+			temp_serviceextinfo->notes_url=mt_strdup(value);
 			if(temp_serviceextinfo->notes_url==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info notes_url.\n");
@@ -3517,7 +3517,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"action_url")){
-			temp_serviceextinfo->action_url=strdup(value);
+			temp_serviceextinfo->action_url=mt_strdup(value);
 			if(temp_serviceextinfo->action_url==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info action_url.\n");
@@ -3526,7 +3526,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"icon_image")){
-			temp_serviceextinfo->icon_image=strdup(value);
+			temp_serviceextinfo->icon_image=mt_strdup(value);
 			if(temp_serviceextinfo->icon_image==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info icon_image.\n");
@@ -3535,7 +3535,7 @@
 			        }
 		        }
 		else if(!strcmp(variable,"icon_image_alt")){
-			temp_serviceextinfo->icon_image_alt=strdup(value);
+			temp_serviceextinfo->icon_image_alt=mt_strdup(value);
 			if(temp_serviceextinfo->icon_image_alt==NULL){
 #ifdef DEBUG1
 				printf("Error: Could not allocate memory for extended service info icon_image_alt.\n");
@@ -3641,8 +3641,8 @@
 			/* if this is the first duplication, use the existing entry */
 			if(first_item==TRUE){
 
-				free(temp_service->host_name);
-				temp_service->host_name=strdup(this_hostlist->host_name);
+				mt_free(temp_service->host_name);
+				temp_service->host_name=mt_strdup(this_hostlist->host_name);
 				if(temp_service->host_name==NULL){
 					xodtemplate_free_hostlist(temp_hostlist);
 					return ERROR;
@@ -3657,7 +3657,7 @@
 
 			/* exit on error */
 			if(result==ERROR){
-				free(host_name);
+				mt_free(host_name);
 				return ERROR;
 		                }
 		        }
@@ -3731,8 +3731,8 @@
 			/* if this is the first duplication, use the existing entry */
 			if(first_item==TRUE){
 
-				free(temp_hostescalation->host_name);
-				temp_hostescalation->host_name=strdup(this_hostlist->host_name);
+				mt_free(temp_hostescalation->host_name);
+				temp_hostescalation->host_name=mt_strdup(this_hostlist->host_name);
 				if(temp_hostescalation->host_name==NULL){
 					xodtemplate_free_hostlist(temp_hostlist);
 					return ERROR;
@@ -3747,7 +3747,7 @@
 
 			/* exit on error */
 			if(result==ERROR){
-				free(host_name);
+				mt_free(host_name);
 				return ERROR;
 		                }
 		        }
@@ -3782,8 +3782,8 @@
 			/* if this is the first duplication,use the existing entry */
 			if(first_item==TRUE){
 
-				free(temp_serviceescalation->host_name);
-				temp_serviceescalation->host_name=strdup(this_hostlist->host_name);
+				mt_free(temp_serviceescalation->host_name);
+				temp_serviceescalation->host_name=mt_strdup(this_hostlist->host_name);
 				if(temp_serviceescalation->host_name==NULL){
 					xodtemplate_free_hostlist(temp_hostlist);
 					return ERROR;
@@ -3834,8 +3834,8 @@
 			/* if this is the first duplication, use the existing entry */
 			if(first_item==TRUE){
 
-				free(temp_serviceescalation->service_description);
-				temp_serviceescalation->service_description=strdup(this_servicelist->service_description);
+				mt_free(temp_serviceescalation->service_description);
+				temp_serviceescalation->service_description=mt_strdup(this_servicelist->service_description);
 				if(temp_serviceescalation->service_description==NULL){
 					xodtemplate_free_servicelist(temp_servicelist);
 					return ERROR;
@@ -3887,10 +3887,10 @@
 			/* if this is the first duplication, use the existing entry if possible */
 			if(first_item==TRUE && temp_serviceescalation->host_name==NULL && temp_serviceescalation->service_description==NULL){
 
-				free(temp_serviceescalation->host_name);
-				temp_serviceescalation->host_name=strdup(this_servicelist->host_name);
-				free(temp_serviceescalation->service_description);
-				temp_serviceescalation->service_description=strdup(this_servicelist->service_description);
+				mt_free(temp_serviceescalation->host_name);
+				temp_serviceescalation->host_name=mt_strdup(this_servicelist->host_name);
+				mt_free(temp_serviceescalation->service_description);
+				temp_serviceescalation->service_description=mt_strdup(this_servicelist->service_description);
 				if(temp_serviceescalation->service_description==NULL){
 					xodtemplate_free_servicelist(temp_servicelist);
 					return ERROR;
@@ -3952,10 +3952,10 @@
 
 				/* existing definition gets first names */
 				if(first_item==TRUE){
-					free(temp_hostdependency->host_name);
-					free(temp_hostdependency->dependent_host_name);
-					temp_hostdependency->host_name=strdup(temp_hostlist->host_name);
-					temp_hostdependency->dependent_host_name=strdup(this_hostlist->host_name);
+					mt_free(temp_hostdependency->host_name);
+					mt_free(temp_hostdependency->dependent_host_name);
+					temp_hostdependency->host_name=mt_strdup(temp_hostlist->host_name);
+					temp_hostdependency->dependent_host_name=mt_strdup(this_hostlist->host_name);
 					first_item=FALSE;
 					continue;
 				        }
@@ -4011,10 +4011,10 @@
 
 				/* existing definition gets first names */
 				if(first_item==TRUE){
-					free(temp_servicedependency->host_name);
-					free(temp_servicedependency->dependent_host_name);
-					temp_servicedependency->host_name=strdup(temp_hostlist->host_name);
-					temp_servicedependency->dependent_host_name=strdup(this_hostlist->host_name);
+					mt_free(temp_servicedependency->host_name);
+					mt_free(temp_servicedependency->dependent_host_name);
+					temp_servicedependency->host_name=mt_strdup(temp_hostlist->host_name);
+					temp_servicedependency->dependent_host_name=mt_strdup(this_hostlist->host_name);
 					first_item=FALSE;
 					continue;
 				        }
@@ -4059,8 +4059,8 @@
 			/* if this is the first duplication, use the existing entry */
 			if(first_item==TRUE){
 
-				free(temp_servicedependency->service_description);
-				temp_servicedependency->service_description=strdup(this_servicelist->service_description);
+				mt_free(temp_servicedependency->service_description);
+				temp_servicedependency->service_description=mt_strdup(this_servicelist->service_description);
 				if(temp_servicedependency->service_description==NULL){
 					xodtemplate_free_servicelist(temp_servicelist);
 					return ERROR;
@@ -4111,8 +4111,8 @@
 			/* if this is the first duplication, use the existing entry */
 			if(first_item==TRUE){
 
-				free(temp_servicedependency->dependent_service_description);
-				temp_servicedependency->dependent_service_description=strdup(this_servicelist->service_description);
+				mt_free(temp_servicedependency->dependent_service_description);
+				temp_servicedependency->dependent_service_description=mt_strdup(this_servicelist->service_description);
 				if(temp_servicedependency->dependent_service_description==NULL){
 					xodtemplate_free_servicelist(temp_servicelist);
 					return ERROR;
@@ -4162,8 +4162,8 @@
 			/* if this is the first duplication, use the existing entry */
 			if(first_item==TRUE){
 
-				free(temp_hostextinfo->host_name);
-				temp_hostextinfo->host_name=strdup(this_hostlist->host_name);
+				mt_free(temp_hostextinfo->host_name);
+				temp_hostextinfo->host_name=mt_strdup(this_hostlist->host_name);
 				if(temp_hostextinfo->host_name==NULL){
 					xodtemplate_free_hostlist(temp_hostlist);
 					return ERROR;
@@ -4211,8 +4211,8 @@
 
 			/* existing definition gets first host name */
 			if(first_item==TRUE){
-				free(temp_serviceextinfo->host_name);
-				temp_serviceextinfo->host_name=strdup(this_hostlist->host_name);
+				mt_free(temp_serviceextinfo->host_name);
+				temp_serviceextinfo->host_name=mt_strdup(this_hostlist->host_name);
 				if(temp_serviceextinfo->host_name==NULL){
 					xodtemplate_free_hostlist(temp_hostlist);
 					return ERROR;
@@ -4253,7 +4253,7 @@
 #endif
 
 	/* allocate memory for a new service definition */
-	new_service=(xodtemplate_service *)malloc(sizeof(xodtemplate_service));
+	new_service=(xodtemplate_service *)mt_malloc(sizeof(xodtemplate_service));
 	if(new_service==NULL){
 #ifdef DEBUG1
 		printf("Error: Could not allocate memory for duplicate definition of service.\n");
@@ -4337,168 +4337,168 @@
 
 	/* allocate memory for and copy string members of service definition (host name provided, DO NOT duplicate hostgroup member!)*/
 	if(temp_service->host_name!=NULL){
-		new_service->host_name=strdup(host_name);
+		new_service->host_name=mt_strdup(host_name);
 		if(new_service->host_name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->template!=NULL){
-		new_service->template=strdup(temp_service->template);
+		new_service->template=mt_strdup(temp_service->template);
 		if(new_service->template==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->name!=NULL){
-		new_service->name=strdup(temp_service->name);
+		new_service->name=mt_strdup(temp_service->name);
 		if(new_service->name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service->template);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service->template);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->service_description!=NULL){
-		new_service->service_description=strdup(temp_service->service_description);
+		new_service->service_description=mt_strdup(temp_service->service_description);
 		if(new_service->service_description==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service->template);
-			free(new_service->name);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service->template);
+			mt_free(new_service->name);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->servicegroups!=NULL){
-		new_service->servicegroups=strdup(temp_service->servicegroups);
+		new_service->servicegroups=mt_strdup(temp_service->servicegroups);
 		if(new_service->servicegroups==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service->template);
-			free(new_service->name);
-			free(new_service->service_description);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service->template);
+			mt_free(new_service->name);
+			mt_free(new_service->service_description);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->check_command!=NULL){
-		new_service->check_command=strdup(temp_service->check_command);
+		new_service->check_command=mt_strdup(temp_service->check_command);
 		if(new_service->check_command==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service->template);
-			free(new_service->name);
-			free(new_service->service_description);
-			free(new_service->servicegroups);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service->template);
+			mt_free(new_service->name);
+			mt_free(new_service->service_description);
+			mt_free(new_service->servicegroups);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->check_period!=NULL){
-		new_service->check_period=strdup(temp_service->check_period);
+		new_service->check_period=mt_strdup(temp_service->check_period);
 		if(new_service->check_period==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service->template);
-			free(new_service->name);
-			free(new_service->service_description);
-			free(new_service->check_command);
-			free(new_service->servicegroups);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service->template);
+			mt_free(new_service->name);
+			mt_free(new_service->service_description);
+			mt_free(new_service->check_command);
+			mt_free(new_service->servicegroups);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->event_handler!=NULL){
-		new_service->event_handler=strdup(temp_service->event_handler);
+		new_service->event_handler=mt_strdup(temp_service->event_handler);
 		if(new_service->event_handler==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service->template);
-			free(new_service->name);
-			free(new_service->service_description);
-			free(new_service->servicegroups);
-			free(new_service->check_command);
-			free(new_service->check_period);
-			free(new_service->servicegroups);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service->template);
+			mt_free(new_service->name);
+			mt_free(new_service->service_description);
+			mt_free(new_service->servicegroups);
+			mt_free(new_service->check_command);
+			mt_free(new_service->check_period);
+			mt_free(new_service->servicegroups);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->notification_period!=NULL){
-		new_service->notification_period=strdup(temp_service->notification_period);
+		new_service->notification_period=mt_strdup(temp_service->notification_period);
 		if(new_service->notification_period==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service->template);
-			free(new_service->name);
-			free(new_service->service_description);
-			free(new_service->servicegroups);
-			free(new_service->check_command);
-			free(new_service->check_period);
-			free(new_service->event_handler);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service->template);
+			mt_free(new_service->name);
+			mt_free(new_service->service_description);
+			mt_free(new_service->servicegroups);
+			mt_free(new_service->check_command);
+			mt_free(new_service->check_period);
+			mt_free(new_service->event_handler);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->contact_groups!=NULL){
-		new_service->contact_groups=strdup(temp_service->contact_groups);
+		new_service->contact_groups=mt_strdup(temp_service->contact_groups);
 		if(new_service->contact_groups==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service->template);
-			free(new_service->name);
-			free(new_service->service_description);
-			free(new_service->servicegroups);
-			free(new_service->check_command);
-			free(new_service->check_period);
-			free(new_service->event_handler);
-			free(new_service->notification_period);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service->template);
+			mt_free(new_service->name);
+			mt_free(new_service->service_description);
+			mt_free(new_service->servicegroups);
+			mt_free(new_service->check_command);
+			mt_free(new_service->check_period);
+			mt_free(new_service->event_handler);
+			mt_free(new_service->notification_period);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
 	if(temp_service->failure_prediction_options!=NULL){
-		new_service->failure_prediction_options=strdup(temp_service->failure_prediction_options);
+		new_service->failure_prediction_options=mt_strdup(temp_service->failure_prediction_options);
 		if(new_service->failure_prediction_options==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service.\n");
 #endif
-			free(new_service->host_name);
-			free(new_service->template);
-			free(new_service->name);
-			free(new_service->service_description);
-			free(new_service->servicegroups);
-			free(new_service->check_command);
-			free(new_service->check_period);
-			free(new_service->event_handler);
-			free(new_service->notification_period);
-			free(new_service->contact_groups);
-			free(new_service);
+			mt_free(new_service->host_name);
+			mt_free(new_service->template);
+			mt_free(new_service->name);
+			mt_free(new_service->service_description);
+			mt_free(new_service->servicegroups);
+			mt_free(new_service->check_command);
+			mt_free(new_service->check_period);
+			mt_free(new_service->event_handler);
+			mt_free(new_service->notification_period);
+			mt_free(new_service->contact_groups);
+			mt_free(new_service);
 			return ERROR;
 		        }
 	        } 
@@ -4526,7 +4526,7 @@
 #endif
 
 	/* allocate memory for a new host escalation definition */
-	new_hostescalation=(xodtemplate_hostescalation *)malloc(sizeof(xodtemplate_hostescalation));
+	new_hostescalation=(xodtemplate_hostescalation *)mt_malloc(sizeof(xodtemplate_hostescalation));
 	if(new_hostescalation==NULL){
 #ifdef DEBUG1
 		printf("Error: Could not allocate memory for duplicate definition of host escalation.\n");
@@ -4561,63 +4561,63 @@
 
 	/* allocate memory for and copy string members of hostescalation definition */
 	if(temp_hostescalation->host_name!=NULL){
-		new_hostescalation->host_name=strdup(host_name);
+		new_hostescalation->host_name=mt_strdup(host_name);
 		if(new_hostescalation->host_name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of host escalation.\n");
 #endif
-			free(new_hostescalation);
+			mt_free(new_hostescalation);
 			return ERROR;
 		        }
 	        } 
 	if(temp_hostescalation->template!=NULL){
-		new_hostescalation->template=strdup(temp_hostescalation->template);
+		new_hostescalation->template=mt_strdup(temp_hostescalation->template);
 		if(new_hostescalation->template==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of host escalation.\n");
 #endif
-			free(new_hostescalation->host_name);
-			free(new_hostescalation);
+			mt_free(new_hostescalation->host_name);
+			mt_free(new_hostescalation);
 			return ERROR;
 		        }
 	        } 
 	if(temp_hostescalation->name!=NULL){
-		new_hostescalation->name=strdup(temp_hostescalation->name);
+		new_hostescalation->name=mt_strdup(temp_hostescalation->name);
 		if(new_hostescalation->name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of host escalation.\n");
 #endif
-			free(new_hostescalation->host_name);
-			free(new_hostescalation->template);
-			free(new_hostescalation);
+			mt_free(new_hostescalation->host_name);
+			mt_free(new_hostescalation->template);
+			mt_free(new_hostescalation);
 			return ERROR;
 		        }
 	        } 
 	if(temp_hostescalation->contact_groups!=NULL){
-		new_hostescalation->contact_groups=strdup(temp_hostescalation->contact_groups);
+		new_hostescalation->contact_groups=mt_strdup(temp_hostescalation->contact_groups);
 		if(new_hostescalation->contact_groups==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of host escalation.\n");
 #endif
-			free(new_hostescalation->host_name);
-			free(new_hostescalation->template);
-			free(new_hostescalation->name);
-			free(new_hostescalation);
+			mt_free(new_hostescalation->host_name);
+			mt_free(new_hostescalation->template);
+			mt_free(new_hostescalation->name);
+			mt_free(new_hostescalation);
 			return ERROR;
 		        }
 	        } 
 
 	if(temp_hostescalation->escalation_period!=NULL){
-		new_hostescalation->escalation_period=strdup(temp_hostescalation->escalation_period);
+		new_hostescalation->escalation_period=mt_strdup(temp_hostescalation->escalation_period);
 		if(new_hostescalation->escalation_period==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of host escalation.\n");
 #endif
-			free(new_hostescalation->contact_groups);
-			free(new_hostescalation->host_name);
-			free(new_hostescalation->template);
-			free(new_hostescalation->name);
-			free(new_hostescalation);
+			mt_free(new_hostescalation->contact_groups);
+			mt_free(new_hostescalation->host_name);
+			mt_free(new_hostescalation->template);
+			mt_free(new_hostescalation->name);
+			mt_free(new_hostescalation);
 			return ERROR;
 		        }
 	        } 
@@ -4644,7 +4644,7 @@
 #endif
 
 	/* allocate memory for a new service escalation definition */
-	new_serviceescalation=(xodtemplate_serviceescalation *)malloc(sizeof(xodtemplate_serviceescalation));
+	new_serviceescalation=(xodtemplate_serviceescalation *)mt_malloc(sizeof(xodtemplate_serviceescalation));
 	if(new_serviceescalation==NULL){
 #ifdef DEBUG1
 		printf("Error: Could not allocate memory for duplicate definition of service escalation.\n");
@@ -4682,101 +4682,101 @@
 
 	/* allocate memory for and copy string members of serviceescalation definition */
 	if(host_name!=NULL){
-		new_serviceescalation->host_name=strdup(host_name);
+		new_serviceescalation->host_name=mt_strdup(host_name);
 		if(new_serviceescalation->host_name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service escalation.\n");
 #endif
-			free(new_serviceescalation);
+			mt_free(new_serviceescalation);
 			return ERROR;
 		        }
 	        } 
 	else if(temp_serviceescalation->host_name!=NULL){
-		new_serviceescalation->host_name=strdup(temp_serviceescalation->host_name);
+		new_serviceescalation->host_name=mt_strdup(temp_serviceescalation->host_name);
 		if(new_serviceescalation->host_name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service escalation.\n");
 #endif
-			free(new_serviceescalation);
+			mt_free(new_serviceescalation);
 			return ERROR;
 		        }
 	        } 
 	if(temp_serviceescalation->template!=NULL){
-		new_serviceescalation->template=strdup(temp_serviceescalation->template);
+		new_serviceescalation->template=mt_strdup(temp_serviceescalation->template);
 		if(new_serviceescalation->template==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service escalation.\n");
 #endif
-			free(new_serviceescalation->host_name);
-			free(new_serviceescalation);
+			mt_free(new_serviceescalation->host_name);
+			mt_free(new_serviceescalation);
 			return ERROR;
 		        }
 	        } 
 	if(temp_serviceescalation->name!=NULL){
-		new_serviceescalation->name=strdup(temp_serviceescalation->name);
+		new_serviceescalation->name=mt_strdup(temp_serviceescalation->name);
 		if(new_serviceescalation->name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service escalation.\n");
 #endif
-			free(new_serviceescalation->host_name);
-			free(new_serviceescalation->template);
-			free(new_serviceescalation);
+			mt_free(new_serviceescalation->host_name);
+			mt_free(new_serviceescalation->template);
+			mt_free(new_serviceescalation);
 			return ERROR;
 		        }
 	        } 
 	if(svc_description!=NULL){
-		new_serviceescalation->service_description=strdup(svc_description);
+		new_serviceescalation->service_description=mt_strdup(svc_description);
 		if(new_serviceescalation->service_description==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service escalation.\n");
 #endif
-			free(new_serviceescalation->host_name);
-			free(new_serviceescalation->template);
-			free(new_serviceescalation->name);
-			free(new_serviceescalation);
+			mt_free(new_serviceescalation->host_name);
+			mt_free(new_serviceescalation->template);
+			mt_free(new_serviceescalation->name);
+			mt_free(new_serviceescalation);
 			return ERROR;
 		        }
 	        } 
 	else if(temp_serviceescalation->service_description!=NULL){
-		new_serviceescalation->service_description=strdup(temp_serviceescalation->service_description);
+		new_serviceescalation->service_description=mt_strdup(temp_serviceescalation->service_description);
 		if(new_serviceescalation->service_description==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service escalation.\n");
 #endif
-			free(new_serviceescalation->host_name);
-			free(new_serviceescalation->template);
-			free(new_serviceescalation->name);
-			free(new_serviceescalation);
+			mt_free(new_serviceescalation->host_name);
+			mt_free(new_serviceescalation->template);
+			mt_free(new_serviceescalation->name);
+			mt_free(new_serviceescalation);
 			return ERROR;
 		        }
 	        } 
 	if(temp_serviceescalation->contact_groups!=NULL){
-		new_serviceescalation->contact_groups=strdup(temp_serviceescalation->contact_groups);
+		new_serviceescalation->contact_groups=mt_strdup(temp_serviceescalation->contact_groups);
 		if(new_serviceescalation->contact_groups==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service escalation.\n");
 #endif
-			free(new_serviceescalation->service_description);
-			free(new_serviceescalation->host_name);
-			free(new_serviceescalation->template);
-			free(new_serviceescalation->name);
-			free(new_serviceescalation);
+			mt_free(new_serviceescalation->service_description);
+			mt_free(new_serviceescalation->host_name);
+			mt_free(new_serviceescalation->template);
+			mt_free(new_serviceescalation->name);
+			mt_free(new_serviceescalation);
 			return ERROR;
 		        }
 	        } 
 
 	if(temp_serviceescalation->escalation_period!=NULL){
-		new_serviceescalation->escalation_period=strdup(temp_serviceescalation->escalation_period);
+		new_serviceescalation->escalation_period=mt_strdup(temp_serviceescalation->escalation_period);
 		if(new_serviceescalation->escalation_period==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service escalation.\n");
 #endif
-			free(new_serviceescalation->contact_groups);
-			free(new_serviceescalation->service_description);
-			free(new_serviceescalation->host_name);
-			free(new_serviceescalation->template);
-			free(new_serviceescalation->name);
-			free(new_serviceescalation);
+			mt_free(new_serviceescalation->contact_groups);
+			mt_free(new_serviceescalation->service_description);
+			mt_free(new_serviceescalation->host_name);
+			mt_free(new_serviceescalation->template);
+			mt_free(new_serviceescalation->name);
+			mt_free(new_serviceescalation);
 			return ERROR;
 		        }
 	        } 
@@ -4803,7 +4803,7 @@
 #endif
 
 	/* allocate memory for a new host dependency definition */
-	new_hostdependency=(xodtemplate_hostdependency *)malloc(sizeof(xodtemplate_hostdependency));
+	new_hostdependency=(xodtemplate_hostdependency *)mt_malloc(sizeof(xodtemplate_hostdependency));
 	if(new_hostdependency==NULL){
 #ifdef DEBUG1
 		printf("Error: Could not allocate memory for duplicate definition of host dependency.\n");
@@ -4839,45 +4839,45 @@
 
 	/* allocate memory for and copy string members of hostdependency definition */
 	if(temp_hostdependency->host_name!=NULL){
-		new_hostdependency->host_name=strdup(master_host_name);
+		new_hostdependency->host_name=mt_strdup(master_host_name);
 		if(new_hostdependency->host_name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of host dependency.\n");
 #endif
-			free(new_hostdependency);
+			mt_free(new_hostdependency);
 			return ERROR;
 		        }
 	        } 
        	if(temp_hostdependency->dependent_host_name!=NULL){
-		new_hostdependency->dependent_host_name=strdup(dependent_host_name);
+		new_hostdependency->dependent_host_name=mt_strdup(dependent_host_name);
 		if(new_hostdependency->dependent_host_name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of host dependency.\n");
 #endif
-			free(new_hostdependency);
+			mt_free(new_hostdependency);
 			return ERROR;
 		        }
 	        } 
 	if(temp_hostdependency->template!=NULL){
-		new_hostdependency->template=strdup(temp_hostdependency->template);
+		new_hostdependency->template=mt_strdup(temp_hostdependency->template);
 		if(new_hostdependency->template==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of host dependency.\n");
 #endif
-			free(new_hostdependency->host_name);
-			free(new_hostdependency);
+			mt_free(new_hostdependency->host_name);
+			mt_free(new_hostdependency);
 			return ERROR;
 		        }
 	        } 
 	if(temp_hostdependency->name!=NULL){
-		new_hostdependency->name=strdup(temp_hostdependency->name);
+		new_hostdependency->name=mt_strdup(temp_hostdependency->name);
 		if(new_hostdependency->name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of host dependency.\n");
 #endif
-			free(new_hostdependency->host_name);
-			free(new_hostdependency->template);
-			free(new_hostdependency);
+			mt_free(new_hostdependency->host_name);
+			mt_free(new_hostdependency->template);
+			mt_free(new_hostdependency);
 			return ERROR;
 		        }
 	        } 
@@ -4904,7 +4904,7 @@
 #endif
 
 	/* allocate memory for a new service dependency definition */
-	new_servicedependency=(xodtemplate_servicedependency *)malloc(sizeof(xodtemplate_servicedependency));
+	new_servicedependency=(xodtemplate_servicedependency *)mt_malloc(sizeof(xodtemplate_servicedependency));
 	if(new_servicedependency==NULL){
 #ifdef DEBUG1
 		printf("Error: Could not allocate memory for duplicate definition of service dependency.\n");
@@ -4945,65 +4945,65 @@
 
 	/* allocate memory for and copy string members of hostdependency definition */
 	if(temp_servicedependency->host_name!=NULL){
-		new_servicedependency->host_name=strdup(master_host_name);
+		new_servicedependency->host_name=mt_strdup(master_host_name);
 		if(new_servicedependency->host_name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service dependency.\n");
 #endif
-			free(new_servicedependency);
+			mt_free(new_servicedependency);
 			return ERROR;
 		        }
 	        } 
 	if(temp_servicedependency->service_description!=NULL){
-		new_servicedependency->service_description=strdup(master_service_description);
+		new_servicedependency->service_description=mt_strdup(master_service_description);
 		if(new_servicedependency->service_description==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service dependency.\n");
 #endif
-			free(new_servicedependency);
+			mt_free(new_servicedependency);
 			return ERROR;
 		        }
 	        } 
        	if(temp_servicedependency->dependent_host_name!=NULL){
-		new_servicedependency->dependent_host_name=strdup(dependent_host_name);
+		new_servicedependency->dependent_host_name=mt_strdup(dependent_host_name);
 		if(new_servicedependency->dependent_host_name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service dependency.\n");
 #endif
-			free(new_servicedependency);
+			mt_free(new_servicedependency);
 			return ERROR;
 		        }
 	        } 
 	if(temp_servicedependency->dependent_service_description!=NULL){
-		new_servicedependency->dependent_service_description=strdup(dependent_service_description);
+		new_servicedependency->dependent_service_description=mt_strdup(dependent_service_description);
 		if(new_servicedependency->dependent_service_description==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service dependency.\n");
 #endif
-			free(new_servicedependency);
+			mt_free(new_servicedependency);
 			return ERROR;
 		        }
 	        } 
 	if(temp_servicedependency->template!=NULL){
-		new_servicedependency->template=strdup(temp_servicedependency->template);
+		new_servicedependency->template=mt_strdup(temp_servicedependency->template);
 		if(new_servicedependency->template==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service dependency.\n");
 #endif
-			free(new_servicedependency->host_name);
-			free(new_servicedependency);
+			mt_free(new_servicedependency->host_name);
+			mt_free(new_servicedependency);
 			return ERROR;
 		        }
 	        } 
 	if(temp_servicedependency->name!=NULL){
-		new_servicedependency->name=strdup(temp_servicedependency->name);
+		new_servicedependency->name=mt_strdup(temp_servicedependency->name);
 		if(new_servicedependency->name==NULL){
 #ifdef DEBUG1
 			printf("Error: Could not allocate memory for duplicate definition of service dependency.\n");
 #endif
-			free(new_servicedependency->host_name);
-			free(new_servicedependency->template);
-			free(new_servicedependency);
+			mt_free(new_servicedependency->host_name);
+			mt_free(new_servicedependency->template);
+			mt_free(new_servicedependency);
 			return ERROR;
 		        }
 	        } 
@@ -5029,7 +5029,7 @@
 	printf("xodtemplate_duplicate_hostextinfo() start\n");
 #endif
 
-	new_hostextinfo=(xodtemplate_hostextinfo *)malloc(sizeof(xodtemplate_hostextinfo));
+	new_hostextinfo=(xodtemplate_hostextinfo *)mt_malloc(sizeof(xodtemplate_hostextinfo));
 	if(new_hostextinfo==NULL){
 #ifdef DEBUG1
 		printf("Error: Could not allocate memory for duplicate definition of extended host info.\n");
@@ -5051,25 +5051,25 @@
 
 	/* duplicate strings (host_name member is passed in) */
 	if(host_name!=NULL)
-		new_hostextinfo->host_name=strdup(host_name);
+		new_hostextinfo->host_name=mt_strdup(host_name);
 	if(this_hostextinfo->template!=NULL)
-		new_hostextinfo->template=strdup(this_hostextinfo->template);
+		new_hostextinfo->template=mt_strdup(this_hostextinfo->template);
 	if(this_hostextinfo->name!=NULL)
-		new_hostextinfo->name=strdup(this_hostextinfo->name);
+		new_hostextinfo->name=mt_strdup(this_hostextinfo->name);
 	if(this_hostextinfo->notes!=NULL)
-		new_hostextinfo->notes=strdup(this_hostextinfo->notes);
+		new_hostextinfo->notes=mt_strdup(this_hostextinfo->notes);
 	if(this_hostextinfo->notes_url!=NULL)
-		new_hostextinfo->notes_url=strdup(this_hostextinfo->notes_url);
+		new_hostextinfo->notes_url=mt_strdup(this_hostextinfo->notes_url);
 	if(this_hostextinfo->action_url!=NULL)
-		new_hostextinfo->action_url=strdup(this_hostextinfo->action_url);
+		new_hostextinfo->action_url=mt_strdup(this_hostextinfo->action_url);
 	if(this_hostextinfo->icon_image!=NULL)
-		new_hostextinfo->icon_image=strdup(this_hostextinfo->icon_image);
+		new_hostextinfo->icon_image=mt_strdup(this_hostextinfo->icon_image);
 	if(this_hostextinfo->icon_image_alt!=NULL)
-		new_hostextinfo->icon_image_alt=strdup(this_hostextinfo->icon_image_alt);
+		new_hostextinfo->icon_image_alt=mt_strdup(this_hostextinfo->icon_image_alt);
 	if(this_hostextinfo->vrml_image!=NULL)
-		new_hostextinfo->vrml_image=strdup(this_hostextinfo->vrml_image);
+		new_hostextinfo->vrml_image=mt_strdup(this_hostextinfo->vrml_image);
 	if(this_hostextinfo->statusmap_image!=NULL)
-		new_hostextinfo->statusmap_image=strdup(this_hostextinfo->statusmap_image);
+		new_hostextinfo->statusmap_image=mt_strdup(this_hostextinfo->statusmap_image);
 
 	/* duplicate non-string members */
 	new_hostextinfo->x_2d=this_hostextinfo->x_2d;
@@ -5104,7 +5104,7 @@
 	printf("xodtemplate_duplicate_serviceextinfo() start\n");
 #endif
 
-	new_serviceextinfo=(xodtemplate_serviceextinfo *)malloc(sizeof(xodtemplate_serviceextinfo));
+	new_serviceextinfo=(xodtemplate_serviceextinfo *)mt_malloc(sizeof(xodtemplate_serviceextinfo));
 	if(new_serviceextinfo==NULL){
 #ifdef DEBUG1
 		printf("Error: Could not allocate memory for duplicate definition of extended service info.\n");
@@ -5127,23 +5127,23 @@
 
 	/* duplicate strings (host_name member is passed in) */
 	if(host_name!=NULL)
-		new_serviceextinfo->host_name=strdup(host_name);
+		new_serviceextinfo->host_name=mt_strdup(host_name);
 	if(this_serviceextinfo->template!=NULL)
-		new_serviceextinfo->template=strdup(this_serviceextinfo->template);
+		new_serviceextinfo->template=mt_strdup(this_serviceextinfo->template);
 	if(this_serviceextinfo->name!=NULL)
-		new_serviceextinfo->name=strdup(this_serviceextinfo->name);
+		new_serviceextinfo->name=mt_strdup(this_serviceextinfo->name);
 	if(this_serviceextinfo->service_description!=NULL)
-		new_serviceextinfo->service_description=strdup(this_serviceextinfo->service_description);
+		new_serviceextinfo->service_description=mt_strdup(this_serviceextinfo->service_description);
 	if(this_serviceextinfo->notes!=NULL)
-		new_serviceextinfo->notes=strdup(this_serviceextinfo->notes);
+		new_serviceextinfo->notes=mt_strdup(this_serviceextinfo->notes);
 	if(this_serviceextinfo->notes_url!=NULL)
-		new_serviceextinfo->notes_url=strdup(this_serviceextinfo->notes_url);
+		new_serviceextinfo->notes_url=mt_strdup(this_serviceextinfo->notes_url);
 	if(this_serviceextinfo->action_url!=NULL)
-		new_serviceextinfo->action_url=strdup(this_serviceextinfo->action_url);
+		new_serviceextinfo->action_url=mt_strdup(this_serviceextinfo->action_url);
 	if(this_serviceextinfo->icon_image!=NULL)
-		new_serviceextinfo->icon_image=strdup(this_serviceextinfo->icon_image);
+		new_serviceextinfo->icon_image=mt_strdup(this_serviceextinfo->icon_image);
 	if(this_serviceextinfo->icon_image_alt!=NULL)
-		new_serviceextinfo->icon_image_alt=strdup(this_serviceextinfo->icon_image_alt);
+		new_serviceextinfo->icon_image_alt=mt_strdup(this_serviceextinfo->icon_image_alt);
 
 	/* add new object to head of list */
 	new_serviceextinfo->next=xodtemplate_serviceextinfo_list;
@@ -5317,12 +5317,12 @@
 
 	/* apply missing properties from template timeperiod... */
 	if(this_timeperiod->timeperiod_name==NULL && template_timeperiod->timeperiod_name!=NULL)
-		this_timeperiod->timeperiod_name=strdup(template_timeperiod->timeperiod_name);
+		this_timeperiod->timeperiod_name=mt_strdup(template_timeperiod->timeperiod_name);
 	if(this_timeperiod->alias==NULL && template_timeperiod->alias!=NULL)
-		this_timeperiod->alias=strdup(template_timeperiod->alias);
+		this_timeperiod->alias=mt_strdup(template_timeperiod->alias);
 	for(x=0;x<7;x++){
 		if(this_timeperiod->timeranges[x]==NULL && template_timeperiod->timeranges[x]!=NULL){
-			this_timeperiod->timeranges[x]=strdup(template_timeperiod->timeranges[x]);
+			this_timeperiod->timeranges[x]=mt_strdup(template_timeperiod->timeranges[x]);
 		        }
 	        }
 
@@ -5373,9 +5373,9 @@
 
 	/* apply missing properties from template command... */
 	if(this_command->command_name==NULL && template_command->command_name!=NULL)
-		this_command->command_name=strdup(template_command->command_name);
+		this_command->command_name=mt_strdup(template_command->command_name);
 	if(this_command->command_line==NULL && template_command->command_line!=NULL)
-		this_command->command_line=strdup(template_command->command_line);
+		this_command->command_line=mt_strdup(template_command->command_line);
 
 #ifdef DEBUG0
 	printf("xodtemplate_resolve_command() end\n");
@@ -5424,11 +5424,11 @@
 
 	/* apply missing properties from template contactgroup... */
 	if(this_contactgroup->contactgroup_name==NULL && template_contactgroup->contactgroup_name!=NULL)
-		this_contactgroup->contactgroup_name=strdup(template_contactgroup->contactgroup_name);
+		this_contactgroup->contactgroup_name=mt_strdup(template_contactgroup->contactgroup_name);
 	if(this_contactgroup->alias==NULL && template_contactgroup->alias!=NULL)
-		this_contactgroup->alias=strdup(template_contactgroup->alias);
+		this_contactgroup->alias=mt_strdup(template_contactgroup->alias);
 	if(this_contactgroup->members==NULL && template_contactgroup->members!=NULL)
-		this_contactgroup->members=strdup(template_contactgroup->members);
+		this_contactgroup->members=mt_strdup(template_contactgroup->members);
 
 #ifdef DEBUG0
 	printf("xodtemplate_resolve_contactgroup() end\n");
@@ -5477,11 +5477,11 @@
 
 	/* apply missing properties from template hostgroup... */
 	if(this_hostgroup->hostgroup_name==NULL && template_hostgroup->hostgroup_name!=NULL)
-		this_hostgroup->hostgroup_name=strdup(template_hostgroup->hostgroup_name);
+		this_hostgroup->hostgroup_name=mt_strdup(template_hostgroup->hostgroup_name);
 	if(this_hostgroup->alias==NULL && template_hostgroup->alias!=NULL)
-		this_hostgroup->alias=strdup(template_hostgroup->alias);
+		this_hostgroup->alias=mt_strdup(template_hostgroup->alias);
 	if(this_hostgroup->members==NULL && template_hostgroup->members!=NULL)
-		this_hostgroup->members=strdup(template_hostgroup->members);
+		this_hostgroup->members=mt_strdup(template_hostgroup->members);
 
 #ifdef DEBUG0
 	printf("xodtemplate_resolve_hostgroup() end\n");
@@ -5530,11 +5530,11 @@
 
 	/* apply missing properties from template servicegroup... */
 	if(this_servicegroup->servicegroup_name==NULL && template_servicegroup->servicegroup_name!=NULL)
-		this_servicegroup->servicegroup_name=strdup(template_servicegroup->servicegroup_name);
+		this_servicegroup->servicegroup_name=mt_strdup(template_servicegroup->servicegroup_name);
 	if(this_servicegroup->alias==NULL && template_servicegroup->alias!=NULL)
-		this_servicegroup->alias=strdup(template_servicegroup->alias);
+		this_servicegroup->alias=mt_strdup(template_servicegroup->alias);
 	if(this_servicegroup->members==NULL && template_servicegroup->members!=NULL)
-		this_servicegroup->members=strdup(template_servicegroup->members);
+		this_servicegroup->members=mt_strdup(template_servicegroup->members);
 
 #ifdef DEBUG0
 	printf("xodtemplate_resolve_servicegroup() end\n");
@@ -5581,21 +5581,21 @@
 
 	/* apply missing properties from template servicedependency... */
 	if(this_servicedependency->servicegroup_name==NULL && template_servicedependency->servicegroup_name!=NULL)
-		this_servicedependency->servicegroup_name=strdup(template_servicedependency->servicegroup_name);
+		this_servicedependency->servicegroup_name=mt_strdup(template_servicedependency->servicegroup_name);
 	if(this_servicedependency->hostgroup_name==NULL && template_servicedependency->hostgroup_name!=NULL)
-		this_servicedependency->hostgroup_name=strdup(template_servicedependency->hostgroup_name);
+		this_servicedependency->hostgroup_name=mt_strdup(template_servicedependency->hostgroup_name);
 	if(this_servicedependency->host_name==NULL && template_servicedependency->host_name!=NULL)
-		this_servicedependency->host_name=strdup(template_servicedependency->host_name);
+		this_servicedependency->host_name=mt_strdup(template_servicedependency->host_name);
 	if(this_servicedependency->service_description==NULL && template_servicedependency->service_description!=NULL)
-		this_servicedependency->service_description=strdup(template_servicedependency->service_description);
+		this_servicedependency->service_description=mt_strdup(template_servicedependency->service_description);
 	if(this_servicedependency->dependent_servicegroup_name==NULL && template_servicedependency->dependent_servicegroup_name!=NULL)
-		this_servicedependency->dependent_servicegroup_name=strdup(template_servicedependency->dependent_servicegroup_name);
+		this_servicedependency->dependent_servicegroup_name=mt_strdup(template_servicedependency->dependent_servicegroup_name);
 	if(this_servicedependency->dependent_hostgroup_name==NULL && template_servicedependency->dependent_hostgroup_name!=NULL)
-		this_servicedependency->dependent_hostgroup_name=strdup(template_servicedependency->dependent_hostgroup_name);
+		this_servicedependency->dependent_hostgroup_name=mt_strdup(template_servicedependency->dependent_hostgroup_name);
 	if(this_servicedependency->dependent_host_name==NULL && template_servicedependency->dependent_host_name!=NULL)
-		this_servicedependency->dependent_host_name=strdup(template_servicedependency->dependent_host_name);
+		this_servicedependency->dependent_host_name=mt_strdup(template_servicedependency->dependent_host_name);
 	if(this_servicedependency->dependent_service_description==NULL && template_servicedependency->dependent_service_description!=NULL)
-		this_servicedependency->dependent_service_description=strdup(template_servicedependency->dependent_service_description);
+		this_servicedependency->dependent_service_description=mt_strdup(template_servicedependency->dependent_service_description);
 	if(this_servicedependency->have_inherits_parent==FALSE && template_servicedependency->have_inherits_parent==TRUE){
 		this_servicedependency->inherits_parent=template_servicedependency->inherits_parent;
 		this_servicedependency->have_inherits_parent=TRUE;
@@ -5662,17 +5662,17 @@
 
 	/* apply missing properties from template serviceescalation... */
 	if(this_serviceescalation->servicegroup_name==NULL && template_serviceescalation->servicegroup_name!=NULL)
-		this_serviceescalation->servicegroup_name=strdup(template_serviceescalation->servicegroup_name);
+		this_serviceescalation->servicegroup_name=mt_strdup(template_serviceescalation->servicegroup_name);
 	if(this_serviceescalation->hostgroup_name==NULL && template_serviceescalation->hostgroup_name!=NULL)
-		this_serviceescalation->hostgroup_name=strdup(template_serviceescalation->hostgroup_name);
+		this_serviceescalation->hostgroup_name=mt_strdup(template_serviceescalation->hostgroup_name);
 	if(this_serviceescalation->host_name==NULL && template_serviceescalation->host_name!=NULL)
-		this_serviceescalation->host_name=strdup(template_serviceescalation->host_name);
+		this_serviceescalation->host_name=mt_strdup(template_serviceescalation->host_name);
 	if(this_serviceescalation->service_description==NULL && template_serviceescalation->service_description!=NULL)
-		this_serviceescalation->service_description=strdup(template_serviceescalation->service_description);
+		this_serviceescalation->service_description=mt_strdup(template_serviceescalation->service_description);
 	if(this_serviceescalation->escalation_period==NULL && template_serviceescalation->escalation_period!=NULL)
-		this_serviceescalation->escalation_period=strdup(template_serviceescalation->escalation_period);
+		this_serviceescalation->escalation_period=mt_strdup(template_serviceescalation->escalation_period);
 	if(this_serviceescalation->contact_groups==NULL && template_serviceescalation->contact_groups!=NULL)
-		this_serviceescalation->contact_groups=strdup(template_serviceescalation->contact_groups);
+		this_serviceescalation->contact_groups=mt_strdup(template_serviceescalation->contact_groups);
 	if(this_serviceescalation->have_first_notification==FALSE && template_serviceescalation->have_first_notification==TRUE){
 		this_serviceescalation->first_notification=template_serviceescalation->first_notification;
 		this_serviceescalation->have_first_notification=TRUE;
@@ -5740,25 +5740,25 @@
 
 	/* apply missing properties from template contact... */
 	if(this_contact->contact_name==NULL && template_contact->contact_name!=NULL)
-		this_contact->contact_name=strdup(template_contact->contact_name);
+		this_contact->contact_name=mt_strdup(template_contact->contact_name);
 	if(this_contact->alias==NULL && template_contact->alias!=NULL)
-		this_contact->alias=strdup(template_contact->alias);
+		this_contact->alias=mt_strdup(template_contact->alias);
 	if(this_contact->email==NULL && template_contact->email!=NULL)
-		this_contact->email=strdup(template_contact->email);
+		this_contact->email=mt_strdup(template_contact->email);
 	if(this_contact->pager==NULL && template_contact->pager!=NULL)
-		this_contact->pager=strdup(template_contact->pager);
+		this_contact->pager=mt_strdup(template_contact->pager);
 	for(x=0;x<MAX_XODTEMPLATE_CONTACT_ADDRESSES;x++){
 		if(this_contact->address[x]==NULL && template_contact->address[x]!=NULL)
-			this_contact->address[x]=strdup(template_contact->address[x]);
+			this_contact->address[x]=mt_strdup(template_contact->address[x]);
 	        }
 	if(this_contact->host_notification_period==NULL && template_contact->host_notification_period!=NULL)
-		this_contact->host_notification_period=strdup(template_contact->host_notification_period);
+		this_contact->host_notification_period=mt_strdup(template_contact->host_notification_period);
 	if(this_contact->service_notification_period==NULL && template_contact->service_notification_period!=NULL)
-		this_contact->service_notification_period=strdup(template_contact->service_notification_period);
+		this_contact->service_notification_period=mt_strdup(template_contact->service_notification_period);
 	if(this_contact->host_notification_commands==NULL && template_contact->host_notification_commands!=NULL)
-		this_contact->host_notification_commands=strdup(template_contact->host_notification_commands);
+		this_contact->host_notification_commands=mt_strdup(template_contact->host_notification_commands);
 	if(this_contact->service_notification_commands==NULL && template_contact->service_notification_commands!=NULL)
-		this_contact->service_notification_commands=strdup(template_contact->service_notification_commands);
+		this_contact->service_notification_commands=mt_strdup(template_contact->service_notification_commands);
 	if(this_contact->have_host_notification_options==FALSE && template_contact->have_host_notification_options==TRUE){
 		this_contact->notify_on_host_down=template_contact->notify_on_host_down;
 		this_contact->notify_on_host_unreachable=template_contact->notify_on_host_unreachable;
@@ -5821,27 +5821,27 @@
 
 	/* apply missing properties from template host... */
 	if(this_host->host_name==NULL && template_host->host_name!=NULL)
-		this_host->host_name=strdup(template_host->host_name);
+		this_host->host_name=mt_strdup(template_host->host_name);
 	if(this_host->alias==NULL && template_host->alias!=NULL)
-		this_host->alias=strdup(template_host->alias);
+		this_host->alias=mt_strdup(template_host->alias);
 	if(this_host->address==NULL && template_host->address!=NULL)
-		this_host->address=strdup(template_host->address);
+		this_host->address=mt_strdup(template_host->address);
 	if(this_host->parents==NULL && template_host->parents!=NULL)
-		this_host->parents=strdup(template_host->parents);
+		this_host->parents=mt_strdup(template_host->parents);
 	if(this_host->hostgroups==NULL && template_host->hostgroups!=NULL)
-		this_host->hostgroups=strdup(template_host->hostgroups);
+		this_host->hostgroups=mt_strdup(template_host->hostgroups);
 	if(this_host->check_command==NULL && template_host->check_command!=NULL)
-		this_host->check_command=strdup(template_host->check_command);
+		this_host->check_command=mt_strdup(template_host->check_command);
 	if(this_host->check_period==NULL && template_host->check_period!=NULL)
-		this_host->check_period=strdup(template_host->check_period);
+		this_host->check_period=mt_strdup(template_host->check_period);
 	if(this_host->event_handler==NULL && template_host->event_handler!=NULL)
-		this_host->event_handler=strdup(template_host->event_handler);
+		this_host->event_handler=mt_strdup(template_host->event_handler);
 	if(this_host->contact_groups==NULL && template_host->contact_groups!=NULL)
-		this_host->contact_groups=strdup(template_host->contact_groups);
+		this_host->contact_groups=mt_strdup(template_host->contact_groups);
 	if(this_host->notification_period==NULL && template_host->notification_period!=NULL)
-		this_host->notification_period=strdup(template_host->notification_period);
+		this_host->notification_period=mt_strdup(template_host->notification_period);
 	if(this_host->failure_prediction_options==NULL && template_host->failure_prediction_options!=NULL)
-		this_host->failure_prediction_options=strdup(template_host->failure_prediction_options);
+		this_host->failure_prediction_options=mt_strdup(template_host->failure_prediction_options);
 	if(this_host->have_check_interval==FALSE && template_host->have_check_interval==TRUE){
 		this_host->check_interval=template_host->check_interval;
 		this_host->have_check_interval=TRUE;
@@ -5970,25 +5970,25 @@
 
 	/* apply missing properties from template service... */
 	if(this_service->hostgroup_name==NULL && template_service->hostgroup_name!=NULL)
-		this_service->hostgroup_name=strdup(template_service->hostgroup_name);
+		this_service->hostgroup_name=mt_strdup(template_service->hostgroup_name);
 	if(this_service->host_name==NULL && template_service->host_name!=NULL)
-		this_service->host_name=strdup(template_service->host_name);
+		this_service->host_name=mt_strdup(template_service->host_name);
 	if(this_service->service_description==NULL && template_service->service_description!=NULL)
-		this_service->service_description=strdup(template_service->service_description);
+		this_service->service_description=mt_strdup(template_service->service_description);
 	if(this_service->servicegroups==NULL && template_service->servicegroups!=NULL)
-		this_service->servicegroups=strdup(template_service->servicegroups);
+		this_service->servicegroups=mt_strdup(template_service->servicegroups);
 	if(this_service->check_command==NULL && template_service->check_command!=NULL)
-		this_service->check_command=strdup(template_service->check_command);
+		this_service->check_command=mt_strdup(template_service->check_command);
 	if(this_service->check_period==NULL && template_service->check_period!=NULL)
-		this_service->check_period=strdup(template_service->check_period);
+		this_service->check_period=mt_strdup(template_service->check_period);
 	if(this_service->event_handler==NULL && template_service->event_handler!=NULL)
-		this_service->event_handler=strdup(template_service->event_handler);
+		this_service->event_handler=mt_strdup(template_service->event_handler);
 	if(this_service->notification_period==NULL && template_service->notification_period!=NULL)
-		this_service->notification_period=strdup(template_service->notification_period);
+		this_service->notification_period=mt_strdup(template_service->notification_period);
 	if(this_service->contact_groups==NULL && template_service->contact_groups!=NULL)
-		this_service->contact_groups=strdup(template_service->contact_groups);
+		this_service->contact_groups=mt_strdup(template_service->contact_groups);
 	if(this_service->failure_prediction_options==NULL && template_service->failure_prediction_options!=NULL)
-		this_service->failure_prediction_options=strdup(template_service->failure_prediction_options);
+		this_service->failure_prediction_options=mt_strdup(template_service->failure_prediction_options);
 	if(this_service->have_max_check_attempts==FALSE && template_service->have_max_check_attempts==TRUE){
 		this_service->max_check_attempts=template_service->max_check_attempts;
 		this_service->have_max_check_attempts=TRUE;
@@ -6130,13 +6130,13 @@
 
 	/* apply missing properties from template hostdependency... */
 	if(this_hostdependency->hostgroup_name==NULL && template_hostdependency->hostgroup_name!=NULL)
-		this_hostdependency->hostgroup_name=strdup(template_hostdependency->hostgroup_name);
+		this_hostdependency->hostgroup_name=mt_strdup(template_hostdependency->hostgroup_name);
 	if(this_hostdependency->dependent_hostgroup_name==NULL && template_hostdependency->dependent_hostgroup_name!=NULL)
-		this_hostdependency->dependent_hostgroup_name=strdup(template_hostdependency->dependent_hostgroup_name);
+		this_hostdependency->dependent_hostgroup_name=mt_strdup(template_hostdependency->dependent_hostgroup_name);
 	if(this_hostdependency->host_name==NULL && template_hostdependency->host_name!=NULL)
-		this_hostdependency->host_name=strdup(template_hostdependency->host_name);
+		this_hostdependency->host_name=mt_strdup(template_hostdependency->host_name);
 	if(this_hostdependency->dependent_host_name==NULL && template_hostdependency->dependent_host_name!=NULL)
-		this_hostdependency->dependent_host_name=strdup(template_hostdependency->dependent_host_name);
+		this_hostdependency->dependent_host_name=mt_strdup(template_hostdependency->dependent_host_name);
 	if(this_hostdependency->have_inherits_parent==FALSE && template_hostdependency->have_inherits_parent==TRUE){
 		this_hostdependency->inherits_parent=template_hostdependency->inherits_parent;
 		this_hostdependency->have_inherits_parent=TRUE;
@@ -6201,11 +6201,11 @@
 
 	/* apply missing properties from template hostescalation... */
 	if(this_hostescalation->host_name==NULL && template_hostescalation->host_name!=NULL)
-		this_hostescalation->host_name=strdup(template_hostescalation->host_name);
+		this_hostescalation->host_name=mt_strdup(template_hostescalation->host_name);
 	if(this_hostescalation->escalation_period==NULL && template_hostescalation->escalation_period!=NULL)
-		this_hostescalation->escalation_period=strdup(template_hostescalation->escalation_period);
+		this_hostescalation->escalation_period=mt_strdup(template_hostescalation->escalation_period);
 	if(this_hostescalation->contact_groups==NULL && template_hostescalation->contact_groups!=NULL)
-		this_hostescalation->contact_groups=strdup(template_hostescalation->contact_groups);
+		this_hostescalation->contact_groups=mt_strdup(template_hostescalation->contact_groups);
 	if(this_hostescalation->have_first_notification==FALSE && template_hostescalation->have_first_notification==TRUE){
 		this_hostescalation->first_notification=template_hostescalation->first_notification;
 		this_hostescalation->have_first_notification=TRUE;
@@ -6271,23 +6271,23 @@
 
 	/* apply missing properties from template hostextinfo... */
 	if(this_hostextinfo->host_name==NULL && template_hostextinfo->host_name!=NULL)
-		this_hostextinfo->host_name=strdup(template_hostextinfo->host_name);
+		this_hostextinfo->host_name=mt_strdup(template_hostextinfo->host_name);
 	if(this_hostextinfo->hostgroup_name==NULL && template_hostextinfo->hostgroup_name!=NULL)
-		this_hostextinfo->hostgroup_name=strdup(template_hostextinfo->hostgroup_name);
+		this_hostextinfo->hostgroup_name=mt_strdup(template_hostextinfo->hostgroup_name);
 	if(this_hostextinfo->notes==NULL && template_hostextinfo->notes!=NULL)
-		this_hostextinfo->notes=strdup(template_hostextinfo->notes);
+		this_hostextinfo->notes=mt_strdup(template_hostextinfo->notes);
 	if(this_hostextinfo->notes_url==NULL && template_hostextinfo->notes_url!=NULL)
-		this_hostextinfo->notes_url=strdup(template_hostextinfo->notes_url);
+		this_hostextinfo->notes_url=mt_strdup(template_hostextinfo->notes_url);
 	if(this_hostextinfo->action_url==NULL && template_hostextinfo->action_url!=NULL)
-		this_hostextinfo->action_url=strdup(template_hostextinfo->action_url);
+		this_hostextinfo->action_url=mt_strdup(template_hostextinfo->action_url);
 	if(this_hostextinfo->icon_image==NULL && template_hostextinfo->icon_image!=NULL)
-		this_hostextinfo->icon_image=strdup(template_hostextinfo->icon_image);
+		this_hostextinfo->icon_image=mt_strdup(template_hostextinfo->icon_image);
 	if(this_hostextinfo->icon_image_alt==NULL && template_hostextinfo->icon_image_alt!=NULL)
-		this_hostextinfo->icon_image_alt=strdup(template_hostextinfo->icon_image_alt);
+		this_hostextinfo->icon_image_alt=mt_strdup(template_hostextinfo->icon_image_alt);
 	if(this_hostextinfo->vrml_image==NULL && template_hostextinfo->vrml_image!=NULL)
-		this_hostextinfo->vrml_image=strdup(template_hostextinfo->vrml_image);
+		this_hostextinfo->vrml_image=mt_strdup(template_hostextinfo->vrml_image);
 	if(this_hostextinfo->statusmap_image==NULL && template_hostextinfo->statusmap_image!=NULL)
-		this_hostextinfo->statusmap_image=strdup(template_hostextinfo->statusmap_image);
+		this_hostextinfo->statusmap_image=mt_strdup(template_hostextinfo->statusmap_image);
 	if(this_hostextinfo->have_2d_coords==FALSE && template_hostextinfo->have_2d_coords==TRUE){
 		this_hostextinfo->x_2d=template_hostextinfo->x_2d;
 		this_hostextinfo->y_2d=template_hostextinfo->y_2d;
@@ -6346,21 +6346,21 @@
 
 	/* apply missing properties from template serviceextinfo... */
 	if(this_serviceextinfo->host_name==NULL && template_serviceextinfo->host_name!=NULL)
-		this_serviceextinfo->host_name=strdup(template_serviceextinfo->host_name);
+		this_serviceextinfo->host_name=mt_strdup(template_serviceextinfo->host_name);
 	if(this_serviceextinfo->hostgroup_name==NULL && template_serviceextinfo->hostgroup_name!=NULL)
-		this_serviceextinfo->hostgroup_name=strdup(template_serviceextinfo->hostgroup_name);
+		this_serviceextinfo->hostgroup_name=mt_strdup(template_serviceextinfo->hostgroup_name);
 	if(this_serviceextinfo->service_description==NULL && template_serviceextinfo->service_description!=NULL)
-		this_serviceextinfo->service_description=strdup(template_serviceextinfo->service_description);
+		this_serviceextinfo->service_description=mt_strdup(template_serviceextinfo->service_description);
 	if(this_serviceextinfo->notes==NULL && template_serviceextinfo->notes!=NULL)
-		this_serviceextinfo->notes=strdup(template_serviceextinfo->notes);
+		this_serviceextinfo->notes=mt_strdup(template_serviceextinfo->notes);
 	if(this_serviceextinfo->notes_url==NULL && template_serviceextinfo->notes_url!=NULL)
-		this_serviceextinfo->notes_url=strdup(template_serviceextinfo->notes_url);
+		this_serviceextinfo->notes_url=mt_strdup(template_serviceextinfo->notes_url);
 	if(this_serviceextinfo->action_url==NULL && template_serviceextinfo->action_url!=NULL)
-		this_serviceextinfo->action_url=strdup(template_serviceextinfo->action_url);
+		this_serviceextinfo->action_url=mt_strdup(template_serviceextinfo->action_url);
 	if(this_serviceextinfo->icon_image==NULL && template_serviceextinfo->icon_image!=NULL)
-		this_serviceextinfo->icon_image=strdup(template_serviceextinfo->icon_image);
+		this_serviceextinfo->icon_image=mt_strdup(template_serviceextinfo->icon_image);
 	if(this_serviceextinfo->icon_image_alt==NULL && template_serviceextinfo->icon_image_alt!=NULL)
-		this_serviceextinfo->icon_image_alt=strdup(template_serviceextinfo->icon_image_alt);
+		this_serviceextinfo->icon_image_alt=mt_strdup(template_serviceextinfo->icon_image_alt);
 
 #ifdef DEBUG0
 	printf("xodtemplate_resolve_serviceextinfo() end\n");
@@ -6415,15 +6415,15 @@
 #endif
 			return ERROR;
 	                }
-		free(temp_contactgroup->members);
+		mt_free(temp_contactgroup->members);
 		temp_contactgroup->members=NULL;
 		for(this_contactlist=temp_contactlist;this_contactlist;this_contactlist=this_contactlist->next){
 
 			/* add this contact to the contactgroup members directive */
 			if(temp_contactgroup->members==NULL)
-				temp_contactgroup->members=strdup(this_contactlist->contact_name);
+				temp_contactgroup->members=mt_strdup(this_contactlist->contact_name);
 			else{
-				new_members=(char *)realloc(temp_contactgroup->members,strlen(temp_contactgroup->members)+strlen(this_contactlist->contact_name)+2);
+				new_members=(char *)mt_realloc(temp_contactgroup->members,strlen(temp_contactgroup->members)+strlen(this_contactlist->contact_name)+2);
 				if(new_members!=NULL){
 					temp_contactgroup->members=new_members;
 					strcat(temp_contactgroup->members,",");
@@ -6443,7 +6443,7 @@
 			continue;
 
 		/* process the list of contactgroups */
-		contactgroup_names=strdup(temp_contact->contactgroups);
+		contactgroup_names=mt_strdup(temp_contact->contactgroups);
 		if(contactgroup_names==NULL)
 			continue;
 		for(temp_ptr=strtok(contactgroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
@@ -6459,15 +6459,15 @@
 				temp_buffer[sizeof(temp_buffer)-1]='\x0';
 				write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-				free(contactgroup_names);
+				mt_free(contactgroup_names);
 				return ERROR;
 			        }
 
 			/* add this contact to the contactgroup members directive */
 			if(temp_contactgroup->members==NULL)
-				temp_contactgroup->members=strdup(temp_contact->contact_name);
+				temp_contactgroup->members=mt_strdup(temp_contact->contact_name);
 			else{
-				new_members=(char *)realloc(temp_contactgroup->members,strlen(temp_contactgroup->members)+strlen(temp_contact->contact_name)+2);
+				new_members=(char *)mt_realloc(temp_contactgroup->members,strlen(temp_contactgroup->members)+strlen(temp_contact->contact_name)+2);
 				if(new_members!=NULL){
 					temp_contactgroup->members=new_members;
 					strcat(temp_contactgroup->members,",");
@@ -6477,7 +6477,7 @@
 		        }
 
 		/* free memory */
-		free(contactgroup_names);
+		mt_free(contactgroup_names);
 	        }
 
 #ifdef DEBUG0
@@ -6524,15 +6524,15 @@
 #endif
 			return ERROR;
 	                }
-		free(temp_hostgroup->members);
+		mt_free(temp_hostgroup->members);
 		temp_hostgroup->members=NULL;
 		for(this_hostlist=temp_hostlist;this_hostlist;this_hostlist=this_hostlist->next){
 
 			/* add this host to the hostgroup members directive */
 			if(temp_hostgroup->members==NULL)
-				temp_hostgroup->members=strdup(this_hostlist->host_name);
+				temp_hostgroup->members=mt_strdup(this_hostlist->host_name);
 			else{
-				new_members=(char *)realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(this_hostlist->host_name)+2);
+				new_members=(char *)mt_realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(this_hostlist->host_name)+2);
 				if(new_members!=NULL){
 					temp_hostgroup->members=new_members;
 					strcat(temp_hostgroup->members,",");
@@ -6552,7 +6552,7 @@
 			continue;
 
 		/* process the list of hostgroups */
-		hostgroup_names=strdup(temp_host->hostgroups);
+		hostgroup_names=mt_strdup(temp_host->hostgroups);
 		if(hostgroup_names==NULL)
 			continue;
 		for(temp_ptr=strtok(hostgroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
@@ -6568,15 +6568,15 @@
 				temp_buffer[sizeof(temp_buffer)-1]='\x0';
 				write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-				free(hostgroup_names);
+				mt_free(hostgroup_names);
 				return ERROR;
 			        }
 
 			/* add this list to the hostgroup members directive */
 			if(temp_hostgroup->members==NULL)
-				temp_hostgroup->members=strdup(temp_host->host_name);
+				temp_hostgroup->members=mt_strdup(temp_host->host_name);
 			else{
-				new_members=(char *)realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(temp_host->host_name)+2);
+				new_members=(char *)mt_realloc(temp_hostgroup->members,strlen(temp_hostgroup->members)+strlen(temp_host->host_name)+2);
 				if(new_members!=NULL){
 					temp_hostgroup->members=new_members;
 					strcat(temp_hostgroup->members,",");
@@ -6586,7 +6586,7 @@
 		        }
 
 		/* free memory */
-		free(hostgroup_names);
+		mt_free(hostgroup_names);
 	        }
 
 #ifdef DEBUG0
@@ -6632,11 +6632,11 @@
 
 			/* this is the host name */
 			if(host_name==NULL)
-				host_name=strdup((temp_ptr[0]==',')?temp_ptr+1:temp_ptr);
+				host_name=mt_strdup((temp_ptr[0]==',')?temp_ptr+1:temp_ptr);
 
 			/* this is the service description */
 			else{
-				service_description=strdup(temp_ptr+1);
+				service_description=mt_strdup(temp_ptr+1);
 
 				/* strsep and strtok cannot be used, as they're used in expand_servicegroups...() */
 				temp_ptr2=strchr(host_name,',');
@@ -6660,9 +6660,9 @@
 					temp_buffer[sizeof(temp_buffer)-1]='\x0';
 					write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-					free(member_names);
-					free(host_name);
-					free(service_description);
+					mt_free(member_names);
+					mt_free(host_name);
+					mt_free(service_description);
 					return ERROR;
 				        }
 
@@ -6670,7 +6670,7 @@
 
 					/* add this service to the servicegroup members directive */
 					if(temp_servicegroup->members==NULL){
-						temp_servicegroup->members=(char *)malloc(strlen(this_servicelist->host_name)+strlen(this_servicelist->service_description)+2);
+						temp_servicegroup->members=(char *)mt_malloc(strlen(this_servicelist->host_name)+strlen(this_servicelist->service_description)+2);
 						if(temp_servicegroup!=NULL){
 							strcpy(temp_servicegroup->members,this_servicelist->host_name);
 							strcat(temp_servicegroup->members,",");
@@ -6678,7 +6678,7 @@
 						        }
 					        }
 					else{
-						new_members=(char *)realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(this_servicelist->host_name)+strlen(this_servicelist->service_description)+3);
+						new_members=(char *)mt_realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(this_servicelist->host_name)+strlen(this_servicelist->service_description)+3);
 						if(new_members!=NULL){
 							temp_servicegroup->members=new_members;
 							strcat(temp_servicegroup->members,",");
@@ -6690,14 +6690,14 @@
 				        }
 				xodtemplate_free_servicelist(temp_servicelist);
 
-				free(host_name);
-				free(service_description);
+				mt_free(host_name);
+				mt_free(service_description);
 				host_name=NULL;
 				service_description=NULL;
 			        }
 		        }
 
-		free(member_names);
+		mt_free(member_names);
 
 		/* error if there were an odd number of items specified (unmatched host/service pair) */
 		if(host_name!=NULL){
@@ -6706,7 +6706,7 @@
 			temp_buffer[sizeof(temp_buffer)-1]='\x0';
 			write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-			free(host_name);
+			mt_free(host_name);
 			return ERROR;
 		        }
 	        }
@@ -6720,7 +6720,7 @@
 			continue;
 
 		/* process the list of servicegroups */
-		servicegroup_names=strdup(temp_service->servicegroups);
+		servicegroup_names=mt_strdup(temp_service->servicegroups);
 		if(servicegroup_names==NULL)
 			continue;
 		for(temp_ptr=strtok(servicegroup_names,",");temp_ptr;temp_ptr=strtok(NULL,",")){
@@ -6736,13 +6736,13 @@
 				temp_buffer[sizeof(temp_buffer)-1]='\x0';
 				write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
 #endif
-				free(servicegroup_names);
+				mt_free(servicegroup_names);
 				return ERROR;
 			        }
 
 			/* add this list to the servicegroup members directive */
 			if(temp_servicegroup->members==NULL){
-				temp_servicegroup->members=(char *)malloc(strlen(temp_service->host_name)+strlen(temp_service->service_description)+2);
+				temp_servicegroup->members=(char *)mt_malloc(strlen(temp_service->host_name)+strlen(temp_service->service_description)+2);
 				if(temp_servicegroup->members!=NULL){
 					strcpy(temp_servicegroup->members,temp_service->host_name);
 					strcat(temp_servicegroup->members,",");
@@ -6750,7 +6750,7 @@
 				        }
 			        }
 			else{
-				new_members=(char *)realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(temp_service->host_name)+strlen(temp_service->service_description)+3);
+				new_members=(char *)mt_realloc(temp_servicegroup->members,strlen(temp_servicegroup->members)+strlen(temp_service->host_name)+strlen(temp_service->service_description)+3);
 				if(new_members!=NULL){
 					temp_servicegroup->members=new_members;
 					strcat(temp_servicegroup->members,",");
@@ -9653,219 +9653,219 @@
 	/* free memory allocated to timeperiod list */
 	for(this_timeperiod=xodtemplate_timeperiod_list;this_timeperiod!=NULL;this_timeperiod=next_timeperiod){
 		next_timeperiod=this_timeperiod->next;
-		free(this_timeperiod->template);
-		free(this_timeperiod->name);
-		free(this_timeperiod->timeperiod_name);
-		free(this_timeperiod->alias);
+		mt_free(this_timeperiod->template);
+		mt_free(this_timeperiod->name);
+		mt_free(this_timeperiod->timeperiod_name);
+		mt_free(this_timeperiod->alias);
 		for(x=0;x<7;x++)
-			free(this_timeperiod->timeranges[x]);
-		free(this_timeperiod);
+			mt_free(this_timeperiod->timeranges[x]);
+		mt_free(this_timeperiod);
 	        }
 	xodtemplate_timeperiod_list=NULL;
 
 	/* free memory allocated to command list */
 	for(this_command=xodtemplate_command_list;this_command!=NULL;this_command=next_command){
 		next_command=this_command->next;
-		free(this_command->template);
-		free(this_command->name);
-		free(this_command->command_name);
-		free(this_command->command_line);
-		free(this_command);
+		mt_free(this_command->template);
+		mt_free(this_command->name);
+		mt_free(this_command->command_name);
+		mt_free(this_command->command_line);
+		mt_free(this_command);
 	        }
 	xodtemplate_command_list=NULL;
 
 	/* free memory allocated to contactgroup list */
 	for(this_contactgroup=xodtemplate_contactgroup_list;this_contactgroup!=NULL;this_contactgroup=next_contactgroup){
 		next_contactgroup=this_contactgroup->next;
-		free(this_contactgroup->template);
-		free(this_contactgroup->name);
-		free(this_contactgroup->contactgroup_name);
-		free(this_contactgroup->alias);
-		free(this_contactgroup->members);
-		free(this_contactgroup);
+		mt_free(this_contactgroup->template);
+		mt_free(this_contactgroup->name);
+		mt_free(this_contactgroup->contactgroup_name);
+		mt_free(this_contactgroup->alias);
+		mt_free(this_contactgroup->members);
+		mt_free(this_contactgroup);
 	        }
 	xodtemplate_contactgroup_list=NULL;
 
 	/* free memory allocated to hostgroup list */
 	for(this_hostgroup=xodtemplate_hostgroup_list;this_hostgroup!=NULL;this_hostgroup=next_hostgroup){
 		next_hostgroup=this_hostgroup->next;
-		free(this_hostgroup->template);
-		free(this_hostgroup->name);
-		free(this_hostgroup->hostgroup_name);
-		free(this_hostgroup->alias);
-		free(this_hostgroup->members);
-		free(this_hostgroup);
+		mt_free(this_hostgroup->template);
+		mt_free(this_hostgroup->name);
+		mt_free(this_hostgroup->hostgroup_name);
+		mt_free(this_hostgroup->alias);
+		mt_free(this_hostgroup->members);
+		mt_free(this_hostgroup);
 	        }
 	xodtemplate_hostgroup_list=NULL;
 
 	/* free memory allocated to servicegroup list */
 	for(this_servicegroup=xodtemplate_servicegroup_list;this_servicegroup!=NULL;this_servicegroup=next_servicegroup){
 		next_servicegroup=this_servicegroup->next;
-		free(this_servicegroup->template);
-		free(this_servicegroup->name);
-		free(this_servicegroup->servicegroup_name);
-		free(this_servicegroup->alias);
-		free(this_servicegroup->members);
-		free(this_servicegroup);
+		mt_free(this_servicegroup->template);
+		mt_free(this_servicegroup->name);
+		mt_free(this_servicegroup->servicegroup_name);
+		mt_free(this_servicegroup->alias);
+		mt_free(this_servicegroup->members);
+		mt_free(this_servicegroup);
 	        }
 	xodtemplate_servicegroup_list=NULL;
 
 	/* free memory allocated to servicedependency list */
 	for(this_servicedependency=xodtemplate_servicedependency_list;this_servicedependency!=NULL;this_servicedependency=next_servicedependency){
 		next_servicedependency=this_servicedependency->next;
-		free(this_servicedependency->template);
-		free(this_servicedependency->name);
-		free(this_servicedependency->servicegroup_name);
-		free(this_servicedependency->hostgroup_name);
-		free(this_servicedependency->host_name);
-		free(this_servicedependency->service_description);
-		free(this_servicedependency->dependent_servicegroup_name);
-		free(this_servicedependency->dependent_hostgroup_name);
-		free(this_servicedependency->dependent_host_name);
-		free(this_servicedependency->dependent_service_description);
-		free(this_servicedependency);
+		mt_free(this_servicedependency->template);
+		mt_free(this_servicedependency->name);
+		mt_free(this_servicedependency->servicegroup_name);
+		mt_free(this_servicedependency->hostgroup_name);
+		mt_free(this_servicedependency->host_name);
+		mt_free(this_servicedependency->service_description);
+		mt_free(this_servicedependency->dependent_servicegroup_name);
+		mt_free(this_servicedependency->dependent_hostgroup_name);
+		mt_free(this_servicedependency->dependent_host_name);
+		mt_free(this_servicedependency->dependent_service_description);
+		mt_free(this_servicedependency);
 	        }
 	xodtemplate_servicedependency_list=NULL;
 
 	/* free memory allocated to serviceescalation list */
 	for(this_serviceescalation=xodtemplate_serviceescalation_list;this_serviceescalation!=NULL;this_serviceescalation=next_serviceescalation){
 		next_serviceescalation=this_serviceescalation->next;
-		free(this_serviceescalation->template);
-		free(this_serviceescalation->name);
-		free(this_serviceescalation->servicegroup_name);
-		free(this_serviceescalation->hostgroup_name);
-		free(this_serviceescalation->host_name);
-		free(this_serviceescalation->service_description);
-		free(this_serviceescalation->escalation_period);
-		free(this_serviceescalation->contact_groups);
-		free(this_serviceescalation);
+		mt_free(this_serviceescalation->template);
+		mt_free(this_serviceescalation->name);
+		mt_free(this_serviceescalation->servicegroup_name);
+		mt_free(this_serviceescalation->hostgroup_name);
+		mt_free(this_serviceescalation->host_name);
+		mt_free(this_serviceescalation->service_description);
+		mt_free(this_serviceescalation->escalation_period);
+		mt_free(this_serviceescalation->contact_groups);
+		mt_free(this_serviceescalation);
 	        }
 	xodtemplate_serviceescalation_list=NULL;
 
 	/* free memory allocated to contact list */
 	for(this_contact=xodtemplate_contact_list;this_contact!=NULL;this_contact=next_contact){
 		next_contact=this_contact->next;
-		free(this_contact->template);
-		free(this_contact->name);
-		free(this_contact->contact_name);
-		free(this_contact->alias);
-		free(this_contact->contactgroups);
-		free(this_contact->email);
-		free(this_contact->pager);
+		mt_free(this_contact->template);
+		mt_free(this_contact->name);
+		mt_free(this_contact->contact_name);
+		mt_free(this_contact->alias);
+		mt_free(this_contact->contactgroups);
+		mt_free(this_contact->email);
+		mt_free(this_contact->pager);
 		for(x=0;x<MAX_XODTEMPLATE_CONTACT_ADDRESSES;x++)
-			free(this_contact->address[x]);
-		free(this_contact->service_notification_period);
-		free(this_contact->service_notification_commands);
-		free(this_contact->host_notification_period);
-		free(this_contact->host_notification_commands);
-		free(this_contact);
+			mt_free(this_contact->address[x]);
+		mt_free(this_contact->service_notification_period);
+		mt_free(this_contact->service_notification_commands);
+		mt_free(this_contact->host_notification_period);
+		mt_free(this_contact->host_notification_commands);
+		mt_free(this_contact);
 	        }
 	xodtemplate_contact_list=NULL;
 
 	/* free memory allocated to host list */
 	for(this_host=xodtemplate_host_list;this_host!=NULL;this_host=next_host){
 		next_host=this_host->next;
-		free(this_host->template);
-		free(this_host->name);
-		free(this_host->host_name);
-		free(this_host->alias);
-		free(this_host->address);
-		free(this_host->parents);
-		free(this_host->hostgroups);
-		free(this_host->check_command);
-		free(this_host->check_period);
-		free(this_host->event_handler);
-		free(this_host->contact_groups);
-		free(this_host->notification_period);
-		free(this_host->failure_prediction_options);
-		free(this_host);
+		mt_free(this_host->template);
+		mt_free(this_host->name);
+		mt_free(this_host->host_name);
+		mt_free(this_host->alias);
+		mt_free(this_host->address);
+		mt_free(this_host->parents);
+		mt_free(this_host->hostgroups);
+		mt_free(this_host->check_command);
+		mt_free(this_host->check_period);
+		mt_free(this_host->event_handler);
+		mt_free(this_host->contact_groups);
+		mt_free(this_host->notification_period);
+		mt_free(this_host->failure_prediction_options);
+		mt_free(this_host);
 	        }
 	xodtemplate_host_list=NULL;
 
 	/* free memory allocated to service list (chained hash) */
 	for(this_service=xodtemplate_service_list;this_service!=NULL;this_service=next_service){
 		next_service=this_service->next;
-		free(this_service->template);
-		free(this_service->name);
-		free(this_service->hostgroup_name);
-		free(this_service->host_name);
-		free(this_service->service_description);
-		free(this_service->servicegroups);
-		free(this_service->check_command);
-		free(this_service->check_period);
-		free(this_service->event_handler);
-		free(this_service->notification_period);
-		free(this_service->contact_groups);
-		free(this_service->failure_prediction_options);
-		free(this_service);
+		mt_free(this_service->template);
+		mt_free(this_service->name);
+		mt_free(this_service->hostgroup_name);
+		mt_free(this_service->host_name);
+		mt_free(this_service->service_description);
+		mt_free(this_service->servicegroups);
+		mt_free(this_service->check_command);
+		mt_free(this_service->check_period);
+		mt_free(this_service->event_handler);
+		mt_free(this_service->notification_period);
+		mt_free(this_service->contact_groups);
+		mt_free(this_service->failure_prediction_options);
+		mt_free(this_service);
 	        }
 	xodtemplate_service_list=NULL;
 
 	/* free memory allocated to hostdependency list */
 	for(this_hostdependency=xodtemplate_hostdependency_list;this_hostdependency!=NULL;this_hostdependency=next_hostdependency){
 		next_hostdependency=this_hostdependency->next;
-		free(this_hostdependency->template);
-		free(this_hostdependency->name);
-		free(this_hostdependency->hostgroup_name);
-		free(this_hostdependency->dependent_hostgroup_name);
-		free(this_hostdependency->host_name);
-		free(this_hostdependency->dependent_host_name);
-		free(this_hostdependency);
+		mt_free(this_hostdependency->template);
+		mt_free(this_hostdependency->name);
+		mt_free(this_hostdependency->hostgroup_name);
+		mt_free(this_hostdependency->dependent_hostgroup_name);
+		mt_free(this_hostdependency->host_name);
+		mt_free(this_hostdependency->dependent_host_name);
+		mt_free(this_hostdependency);
 	        }
 	xodtemplate_hostdependency_list=NULL;
 
 	/* free memory allocated to hostescalation list */
 	for(this_hostescalation=xodtemplate_hostescalation_list;this_hostescalation!=NULL;this_hostescalation=next_hostescalation){
 		next_hostescalation=this_hostescalation->next;
-		free(this_hostescalation->template);
-		free(this_hostescalation->name);
-		free(this_hostescalation->hostgroup_name);
-		free(this_hostescalation->host_name);
-		free(this_hostescalation->escalation_period);
-		free(this_hostescalation->contact_groups);
-		free(this_hostescalation);
+		mt_free(this_hostescalation->template);
+		mt_free(this_hostescalation->name);
+		mt_free(this_hostescalation->hostgroup_name);
+		mt_free(this_hostescalation->host_name);
+		mt_free(this_hostescalation->escalation_period);
+		mt_free(this_hostescalation->contact_groups);
+		mt_free(this_hostescalation);
 	        }
 	xodtemplate_hostescalation_list=NULL;
 
 	/* free memory allocated to hostextinfo list */
 	for(this_hostextinfo=xodtemplate_hostextinfo_list;this_hostextinfo!=NULL;this_hostextinfo=next_hostextinfo){
 		next_hostextinfo=this_hostextinfo->next;
-		free(this_hostextinfo->template);
-		free(this_hostextinfo->name);
-		free(this_hostextinfo->host_name);
-		free(this_hostextinfo->hostgroup_name);
-		free(this_hostextinfo->notes);
-		free(this_hostextinfo->notes_url);
-		free(this_hostextinfo->action_url);
-		free(this_hostextinfo->icon_image);
-		free(this_hostextinfo->icon_image_alt);
-		free(this_hostextinfo->vrml_image);
-		free(this_hostextinfo->statusmap_image);
-		free(this_hostextinfo);
+		mt_free(this_hostextinfo->template);
+		mt_free(this_hostextinfo->name);
+		mt_free(this_hostextinfo->host_name);
+		mt_free(this_hostextinfo->hostgroup_name);
+		mt_free(this_hostextinfo->notes);
+		mt_free(this_hostextinfo->notes_url);
+		mt_free(this_hostextinfo->action_url);
+		mt_free(this_hostextinfo->icon_image);
+		mt_free(this_hostextinfo->icon_image_alt);
+		mt_free(this_hostextinfo->vrml_image);
+		mt_free(this_hostextinfo->statusmap_image);
+		mt_free(this_hostextinfo);
 	        }
 	xodtemplate_hostextinfo_list=NULL;
 
 	/* free memory allocated to serviceextinfo list */
 	for(this_serviceextinfo=xodtemplate_serviceextinfo_list;this_serviceextinfo!=NULL;this_serviceextinfo=next_serviceextinfo){
 		next_serviceextinfo=this_serviceextinfo->next;
-		free(this_serviceextinfo->template);
-		free(this_serviceextinfo->name);
-		free(this_serviceextinfo->host_name);
-		free(this_serviceextinfo->hostgroup_name);
-		free(this_serviceextinfo->service_description);
-		free(this_serviceextinfo->notes);
-		free(this_serviceextinfo->notes_url);
-		free(this_serviceextinfo->action_url);
-		free(this_serviceextinfo->icon_image);
-		free(this_serviceextinfo->icon_image_alt);
-		free(this_serviceextinfo);
+		mt_free(this_serviceextinfo->template);
+		mt_free(this_serviceextinfo->name);
+		mt_free(this_serviceextinfo->host_name);
+		mt_free(this_serviceextinfo->hostgroup_name);
+		mt_free(this_serviceextinfo->service_description);
+		mt_free(this_serviceextinfo->notes);
+		mt_free(this_serviceextinfo->notes_url);
+		mt_free(this_serviceextinfo->action_url);
+		mt_free(this_serviceextinfo->icon_image);
+		mt_free(this_serviceextinfo->icon_image_alt);
+		mt_free(this_serviceextinfo);
 	        }
 	xodtemplate_serviceextinfo_list=NULL;
 
 	/* free memory for the config file names */
 	for(x=0;x<xodtemplate_current_config_file;x++)
-		free(xodtemplate_config_files[x]);
-	free(xodtemplate_config_files);
+		mt_free(xodtemplate_config_files[x]);
+	mt_free(xodtemplate_config_files);
 	xodtemplate_current_config_file=0;
 
 
@@ -9889,8 +9889,8 @@
 	/* free memory allocated to contact name list */
 	for(this_contactlist=temp_list;this_contactlist!=NULL;this_contactlist=next_contactlist){
 		next_contactlist=this_contactlist->next;
-		free(this_contactlist->contact_name);
-		free(this_contactlist);
+		mt_free(this_contactlist->contact_name);
+		mt_free(this_contactlist);
 	        }
 
 	temp_list=NULL;
@@ -9925,8 +9925,8 @@
 		for(temp_item=*list;temp_item!=NULL;temp_item=temp_item->next){
 			if(temp_item->next==item){
 				temp_item->next=item->next;
-				free(item->contact_name);
-				free(item);
+				mt_free(item->contact_name);
+				mt_free(item);
 				break;
 			        }
 		        }
@@ -9953,8 +9953,8 @@
 	/* free memory allocated to host name list */
 	for(this_hostlist=temp_list;this_hostlist!=NULL;this_hostlist=next_hostlist){
 		next_hostlist=this_hostlist->next;
-		free(this_hostlist->host_name);
-		free(this_hostlist);
+		mt_free(this_hostlist->host_name);
+		mt_free(this_hostlist);
 	        }
 
 	temp_list=NULL;
@@ -9989,8 +9989,8 @@
 		for(temp_item=*list;temp_item!=NULL;temp_item=temp_item->next){
 			if(temp_item->next==item){
 				temp_item->next=item->next;
-				free(item->host_name);
-				free(item);
+				mt_free(item->host_name);
+				mt_free(item);
 				break;
 			        }
 		        }
@@ -10016,9 +10016,9 @@
 	/* free memory allocated to service name list */
 	for(this_servicelist=temp_list;this_servicelist!=NULL;this_servicelist=next_servicelist){
 		next_servicelist=this_servicelist->next;
-		free(this_servicelist->host_name);
-		free(this_servicelist->service_description);
-		free(this_servicelist);
+		mt_free(this_servicelist->host_name);
+		mt_free(this_servicelist->service_description);
+		mt_free(this_servicelist);
 	        }
 
 	temp_list=NULL;
@@ -10053,9 +10053,9 @@
 		for(temp_item=*list;temp_item!=NULL;temp_item=temp_item->next){
 			if(temp_item->next==item){
 				temp_item->next=item->next;
-				free(item->host_name);
-				free(item->service_description);
-				free(item);
+				mt_free(item->host_name);
+				mt_free(item->service_description);
+				mt_free(item);
 				break;
 			        }
 		        }
@@ -10141,7 +10141,7 @@
 	if(list==NULL || contacts==NULL)
 		return ERROR;
 
-	contact_names=strdup(contacts);
+	contact_names=mt_strdup(contacts);
 	if(contact_names==NULL)
 		return ERROR;
 
@@ -10163,7 +10163,7 @@
 
 			/* compile regular expression */
 			if(regcomp(&preg,temp_ptr,0)){
-				free(contact_names);
+				mt_free(contact_names);
 				return ERROR;
 		                }
 			
@@ -10237,7 +10237,7 @@
 	        }
 
 	/* free memory */
-	free(contact_names);
+	mt_free(contact_names);
 
 #ifdef DEBUG0
 	printf("xodtemplate_expand_contacts2() end\n");
@@ -10267,14 +10267,14 @@
 		return OK;
 
 	/* allocate memory for a new list item */
-	new_item=(xodtemplate_contactlist *)malloc(sizeof(xodtemplate_contactlist));
+	new_item=(xodtemplate_contactlist *)mt_malloc(sizeof(xodtemplate_contactlist));
 	if(new_item==NULL)
 		return ERROR;
 
 	/* save the contact name */
-	new_item->contact_name=strdup(contact_name);
+	new_item->contact_name=mt_strdup(contact_name);
 	if(new_item->contact_name==NULL){
-		free(new_item);
+		mt_free(new_item);
 		return ERROR;
 	        }
 
@@ -10379,7 +10379,7 @@
 		return ERROR;
 
 	/* allocate memory for hostgroup name list */
-	hostgroup_names=strdup(hostgroups);
+	hostgroup_names=mt_strdup(hostgroups);
 	if(hostgroup_names==NULL)
 		return ERROR;
 
@@ -10402,7 +10402,7 @@
 
 			/* compile regular expression */
 			if(regcomp(&preg,temp_ptr,0)){
-				free(hostgroup_names);
+				mt_free(hostgroup_names);
 				return ERROR;
 		                }
 			
@@ -10473,7 +10473,7 @@
 	        }
 
 	/* free memory */
-	free(hostgroup_names);
+	mt_free(hostgroup_names);
 
 #ifdef DEBUG0
 	printf("xodtemplate_expand_hostgroups() end\n");
@@ -10507,7 +10507,7 @@
 	if(list==NULL || hosts==NULL)
 		return ERROR;
 
-	host_names=strdup(hosts);
+	host_names=mt_strdup(hosts);
 	if(host_names==NULL)
 		return ERROR;
 
@@ -10529,7 +10529,7 @@
 
 			/* compile regular expression */
 			if(regcomp(&preg,temp_ptr,0)){
-				free(host_names);
+				mt_free(host_names);
 				return ERROR;
 		                }
 			
@@ -10603,7 +10603,7 @@
 	        }
 
 	/* free memory */
-	free(host_names);
+	mt_free(host_names);
 
 #ifdef DEBUG0
 	printf("xodtemplate_expand_hosts() end\n");
@@ -10630,7 +10630,7 @@
 		return OK;
 
 	/* save a copy of the members */
-	group_members=strdup(temp_hostgroup->members);
+	group_members=mt_strdup(temp_hostgroup->members);
 	if(group_members==NULL)
 		return ERROR;
 
@@ -10646,7 +10646,7 @@
 		xodtemplate_add_host_to_hostlist(list,member_name);
 	        }
 
-	free(group_members);
+	mt_free(group_members);
 
 	return OK;
         }
@@ -10668,14 +10668,14 @@
 		return OK;
 
 	/* allocate memory for a new list item */
-	new_item=(xodtemplate_hostlist *)malloc(sizeof(xodtemplate_hostlist));
+	new_item=(xodtemplate_hostlist *)mt_malloc(sizeof(xodtemplate_hostlist));
 	if(new_item==NULL)
 		return ERROR;
 
 	/* save the host name */
-	new_item->host_name=strdup(host_name);
+	new_item->host_name=mt_strdup(host_name);
 	if(new_item->host_name==NULL){
-		free(new_item);
+		mt_free(new_item);
 		return ERROR;
 	        }
 
@@ -10777,7 +10777,7 @@
 		return ERROR;
 
 	/* allocate memory for servicegroup name list */
-	servicegroup_names=strdup(servicegroups);
+	servicegroup_names=mt_strdup(servicegroups);
 	if(servicegroup_names==NULL)
 		return ERROR;
 
@@ -10801,7 +10801,7 @@
 
 			/* compile regular expression */
 			if(regcomp(&preg,temp_ptr,0)){
-				free(servicegroup_names);
+				mt_free(servicegroup_names);
 				return ERROR;
 		                }
 			
@@ -10873,7 +10873,7 @@
 	        }
 
 	/* free memory */
-	free(servicegroup_names);
+	mt_free(servicegroup_names);
 
 #ifdef DEBUG0
 	printf("xodtemplate_expand_servicegroups() end\n");
@@ -10918,7 +10918,7 @@
 			return ERROR;
 	        }
 
-	service_names=strdup(services);
+	service_names=mt_strdup(services);
 	if(service_names==NULL){
 		if(use_regexp_host==TRUE)
 			regfree(&preg2);
@@ -10945,7 +10945,7 @@
 			if(regcomp(&preg,temp_ptr,0)){
 				if(use_regexp_host==TRUE)
 					regfree(&preg2);
-				free(service_names);
+				mt_free(service_names);
 				return ERROR;
 			        }
 			}
@@ -11044,7 +11044,7 @@
 
 	if(use_regexp_host==TRUE)
 		regfree(&preg2);
-	free(service_names);
+	mt_free(service_names);
 
 #ifdef DEBUG0
 	printf("xodtemplate_expand_services() end\n");
@@ -11072,7 +11072,7 @@
 		return OK;
 
 	/* save a copy of the members */
-	group_members=strdup(temp_servicegroup->members);
+	group_members=mt_strdup(temp_servicegroup->members);
 	if(group_members==NULL)
 		return ERROR;
 
@@ -11087,9 +11087,9 @@
 
 		/* host name */
 		if(host_name==NULL){
-			host_name=strdup(member_name);
+			host_name=mt_strdup(member_name);
 			if(host_name==NULL){
-				free(group_members);
+				mt_free(group_members);
 				return ERROR;
 			        }
 		        }
@@ -11100,12 +11100,12 @@
 			/* add service to the list */
 			xodtemplate_add_service_to_servicelist(list,host_name,member_name);
 
-			free(host_name);
+			mt_free(host_name);
 			host_name=NULL;
 		        }
 	        }
 
-	free(group_members);
+	mt_free(group_members);
 
 	return OK;
         }
@@ -11127,15 +11127,15 @@
 		return OK;
 
 	/* allocate memory for a new list item */
-	new_item=(xodtemplate_servicelist *)malloc(sizeof(xodtemplate_servicelist));
+	new_item=(xodtemplate_servicelist *)mt_malloc(sizeof(xodtemplate_servicelist));
 	if(new_item==NULL)
 		return ERROR;
 
 	/* save the host name and service description */
-	new_item->host_name=strdup(host_name);
-	new_item->service_description=strdup(description);
+	new_item->host_name=mt_strdup(host_name);
+	new_item->service_description=mt_strdup(description);
 	if(new_item->host_name==NULL || new_item->service_description==NULL){
-		free(new_item);
+		mt_free(new_item);
 		return ERROR;
 	        }
 
diff -urN /home/exon/Nagios/xdata/xpddefault.c ./xdata/xpddefault.c
--- /home/exon/Nagios/xdata/xpddefault.c	2004-12-01 20:16:03.000000000 +0100
+++ ./xdata/xpddefault.c	2004-12-01 22:48:42.000000000 +0100
@@ -98,9 +98,9 @@
 
 	/* make sure we have some templates defined */
 	if(xpddefault_host_perfdata_file_template==NULL)
-		xpddefault_host_perfdata_file_template=strdup(DEFAULT_HOST_PERFDATA_FILE_TEMPLATE);
+		xpddefault_host_perfdata_file_template=mt_strdup(DEFAULT_HOST_PERFDATA_FILE_TEMPLATE);
 	if(xpddefault_service_perfdata_file_template==NULL)
-		xpddefault_service_perfdata_file_template=strdup(DEFAULT_SERVICE_PERFDATA_FILE_TEMPLATE);
+		xpddefault_service_perfdata_file_template=mt_strdup(DEFAULT_SERVICE_PERFDATA_FILE_TEMPLATE);
 
 	/* process special chars in templates */
 	xpddefault_preprocess_file_templates(xpddefault_host_perfdata_file_template);
@@ -123,7 +123,7 @@
 			snprintf(buffer,sizeof(buffer),"Warning: Host performance command '%s' was not found - host performance data will not be processed!\n",temp_command_name);
 			buffer[sizeof(buffer)-1]='\x0';
 			write_to_logs_and_console(buffer,NSLOG_RUNTIME_WARNING,TRUE);
-			free(xpddefault_host_perfdata_command);
+			mt_free(xpddefault_host_perfdata_command);
 			xpddefault_host_perfdata_command=NULL;
 		        }
 	        }
@@ -139,7 +139,7 @@
 			snprintf(buffer,sizeof(buffer),"Warning: Service performance command '%s' was not found - service performance data will not be processed!\n",temp_command_name);
 			buffer[sizeof(buffer)-1]='\x0';
 			write_to_logs_and_console(buffer,NSLOG_RUNTIME_WARNING,TRUE);
-			free(xpddefault_service_perfdata_command);
+			mt_free(xpddefault_service_perfdata_command);
 			xpddefault_service_perfdata_command=NULL;
 		        }
 	        }
@@ -155,7 +155,7 @@
 			snprintf(buffer,sizeof(buffer),"Warning: Host performance file processing command '%s' was not found - host performance data file will not be processed!\n",temp_command_name);
 			buffer[sizeof(buffer)-1]='\x0';
 			write_to_logs_and_console(buffer,NSLOG_RUNTIME_WARNING,TRUE);
-			free(xpddefault_host_perfdata_file_processing_command);
+			mt_free(xpddefault_host_perfdata_file_processing_command);
 			xpddefault_host_perfdata_file_processing_command=NULL;
 		        }
 	        }
@@ -171,7 +171,7 @@
 			snprintf(buffer,sizeof(buffer),"Warning: Service performance file processing command '%s' was not found - service performance data file will not be processed!\n",temp_command_name);
 			buffer[sizeof(buffer)-1]='\x0';
 			write_to_logs_and_console(buffer,NSLOG_RUNTIME_WARNING,TRUE);
-			free(xpddefault_service_perfdata_file_processing_command);
+			mt_free(xpddefault_service_perfdata_file_processing_command);
 			xpddefault_service_perfdata_file_processing_command=NULL;
 		        }
 	        }
@@ -186,21 +186,21 @@
 
 	/* save the host perf data file macro */
 	if(macro_x[MACRO_HOSTPERFDATAFILE]!=NULL){
-		free(macro_x[MACRO_HOSTPERFDATAFILE]);
+		mt_free(macro_x[MACRO_HOSTPERFDATAFILE]);
 		macro_x[MACRO_HOSTPERFDATAFILE]=NULL;
 	        }
 	if(xpddefault_host_perfdata_file!=NULL)
-		macro_x[MACRO_HOSTPERFDATAFILE]=(char *)strdup(xpddefault_host_perfdata_file);
+		macro_x[MACRO_HOSTPERFDATAFILE]=(char *)mt_strdup(xpddefault_host_perfdata_file);
 	if(macro_x[MACRO_HOSTPERFDATAFILE]!=NULL)
 		strip(macro_x[MACRO_HOSTPERFDATAFILE]);
 
 	/* save the service perf data file macro */
 	if(macro_x[MACRO_SERVICEPERFDATAFILE]!=NULL){
-		free(macro_x[MACRO_SERVICEPERFDATAFILE]);
+		mt_free(macro_x[MACRO_SERVICEPERFDATAFILE]);
 		macro_x[MACRO_SERVICEPERFDATAFILE]=NULL;
 	        }
 	if(xpddefault_service_perfdata_file!=NULL)
-		macro_x[MACRO_SERVICEPERFDATAFILE]=(char *)strdup(xpddefault_service_perfdata_file);
+		macro_x[MACRO_SERVICEPERFDATAFILE]=(char *)mt_strdup(xpddefault_service_perfdata_file);
 	if(macro_x[MACRO_SERVICEPERFDATAFILE]!=NULL)
 		strip(macro_x[MACRO_SERVICEPERFDATAFILE]);
 
@@ -230,7 +230,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -280,22 +280,22 @@
 		        }
 
 		else if(!strcmp(variable,"host_perfdata_command"))
-			xpddefault_host_perfdata_command=strdup(value);
+			xpddefault_host_perfdata_command=mt_strdup(value);
 
 		else if(!strcmp(variable,"service_perfdata_command"))
-			xpddefault_service_perfdata_command=strdup(value);
+			xpddefault_service_perfdata_command=mt_strdup(value);
 
 		else if(!strcmp(variable,"host_perfdata_file_template"))
-			xpddefault_host_perfdata_file_template=strdup(value);
+			xpddefault_host_perfdata_file_template=mt_strdup(value);
 
 		else if(!strcmp(variable,"service_perfdata_file_template"))
-			xpddefault_service_perfdata_file_template=strdup(value);
+			xpddefault_service_perfdata_file_template=mt_strdup(value);
 
 		else if(!strcmp(variable,"host_perfdata_file"))
-			xpddefault_host_perfdata_file=strdup(value);
+			xpddefault_host_perfdata_file=mt_strdup(value);
 
 		else if(!strcmp(variable,"service_perfdata_file"))
-			xpddefault_service_perfdata_file=strdup(value);
+			xpddefault_service_perfdata_file=mt_strdup(value);
 
 		else if(!strcmp(variable,"host_perfdata_file_mode")){
 			if(!strstr(value,"w"))
@@ -318,14 +318,14 @@
 			xpddefault_service_perfdata_file_processing_interval=strtoul(value,NULL,0);
 
 		else if(!strcmp(variable,"host_perfdata_file_processing_command"))
-			xpddefault_host_perfdata_file_processing_command=strdup(value);
+			xpddefault_host_perfdata_file_processing_command=mt_strdup(value);
 
 		else if(!strcmp(variable,"service_perfdata_file_processing_command"))
-			xpddefault_service_perfdata_file_processing_command=strdup(value);
+			xpddefault_service_perfdata_file_processing_command=mt_strdup(value);
 	        }
 
 	/* free memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	return OK;
@@ -351,35 +351,35 @@
 
 	/* free memory */
 	if(xpddefault_host_perfdata_command!=NULL){
-		free(xpddefault_host_perfdata_command);
+		mt_free(xpddefault_host_perfdata_command);
 		xpddefault_host_perfdata_command=NULL;
 	        }
 	if(xpddefault_service_perfdata_command!=NULL){
-		free(xpddefault_service_perfdata_command);
+		mt_free(xpddefault_service_perfdata_command);
 		xpddefault_service_perfdata_command=NULL;
 	        }
 	if(xpddefault_host_perfdata_file_template!=NULL){
-		free(xpddefault_host_perfdata_file_template);
+		mt_free(xpddefault_host_perfdata_file_template);
 		xpddefault_host_perfdata_file_template=NULL;
 	        }
 	if(xpddefault_service_perfdata_file_template!=NULL){
-		free(xpddefault_service_perfdata_file_template);
+		mt_free(xpddefault_service_perfdata_file_template);
 		xpddefault_service_perfdata_file_template=NULL;
 	        }
 	if(xpddefault_host_perfdata_file!=NULL){
-		free(xpddefault_host_perfdata_file);
+		mt_free(xpddefault_host_perfdata_file);
 		xpddefault_host_perfdata_file=NULL;
 	        }
 	if(xpddefault_service_perfdata_file!=NULL){
-		free(xpddefault_service_perfdata_file);
+		mt_free(xpddefault_service_perfdata_file);
 		xpddefault_service_perfdata_file=NULL;
 	        }
 	if(xpddefault_host_perfdata_file_processing_command!=NULL){
-		free(xpddefault_host_perfdata_file_processing_command);
+		mt_free(xpddefault_host_perfdata_file_processing_command);
 		xpddefault_host_perfdata_file_processing_command=NULL;
 	        }
 	if(xpddefault_service_perfdata_file_processing_command!=NULL){
-		free(xpddefault_service_perfdata_file_processing_command);
+		mt_free(xpddefault_service_perfdata_file_processing_command);
 		xpddefault_service_perfdata_file_processing_command=NULL;
 	        }
 
@@ -615,7 +615,7 @@
 		return OK;
 
 	/* allocate temporary buffer */
-	tempbuf=(char *)malloc(strlen(template)+1);
+	tempbuf=(char *)mt_malloc(strlen(template)+1);
 	if(tempbuf==NULL)
 		return ERROR;
 	strcpy(tempbuf,"");
@@ -643,7 +643,7 @@
 	tempbuf[y]='\x0';
 
 	strcpy(template,tempbuf);
-	free(tempbuf);
+	mt_free(tempbuf);
 
 	return OK;
         }
diff -urN /home/exon/Nagios/xdata/xrddefault.c ./xdata/xrddefault.c
--- /home/exon/Nagios/xdata/xrddefault.c	2004-11-05 15:18:53.000000000 +0100
+++ ./xdata/xrddefault.c	2004-12-01 22:48:42.000000000 +0100
@@ -99,7 +99,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -129,13 +129,13 @@
 	        }
 
 	/* free memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	/* save the retention file macro */
 	if(macro_x[MACRO_RETENTIONDATAFILE]!=NULL)
-		free(macro_x[MACRO_RETENTIONDATAFILE]);
-	macro_x[MACRO_RETENTIONDATAFILE]=(char *)strdup(xrddefault_retention_file);
+		mt_free(macro_x[MACRO_RETENTIONDATAFILE]);
+	macro_x[MACRO_RETENTIONDATAFILE]=(char *)mt_strdup(xrddefault_retention_file);
 	if(macro_x[MACRO_RETENTIONDATAFILE]!=NULL)
 		strip(macro_x[MACRO_RETENTIONDATAFILE]);
 
@@ -387,7 +387,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -447,7 +447,7 @@
 						temp_host->last_hard_state_change=temp_host->last_state_change;
 				        }
 
-				free(host_name);
+				mt_free(host_name);
 				host_name=NULL;
 				temp_host=NULL;
 				break;
@@ -479,9 +479,9 @@
 						temp_service->last_hard_state_change=temp_service->last_state_change;
 				        }
 
-				free(host_name);
+				mt_free(host_name);
 				host_name=NULL;
-				free(service_description);
+				mt_free(service_description);
 				service_description=NULL;
 				temp_service=NULL;
 				break;
@@ -579,10 +579,10 @@
 							temp_buffer2[sizeof(temp_buffer2)-1]='\x0';
 							temp_ptr=my_strtok(temp_buffer2,"!");
 							temp_command=find_command(temp_ptr);
-							temp_ptr=strdup(val);
+							temp_ptr=mt_strdup(val);
 
 							if(temp_command!=NULL && temp_ptr!=NULL){
-								free(global_host_event_handler);
+								mt_free(global_host_event_handler);
 								global_host_event_handler=temp_ptr;
 							        }
 						        }
@@ -595,10 +595,10 @@
 							temp_buffer2[sizeof(temp_buffer2)-1]='\x0';
 							temp_ptr=my_strtok(temp_buffer2,"!");
 							temp_command=find_command(temp_ptr);
-							temp_ptr=strdup(val);
+							temp_ptr=mt_strdup(val);
 
 							if(temp_command!=NULL && temp_ptr!=NULL){
-								free(global_service_event_handler);
+								mt_free(global_service_event_handler);
 								global_service_event_handler=temp_ptr;
 							        }
 						        }
@@ -608,7 +608,7 @@
 
 			case XRDDEFAULT_HOST_DATA:
 				if(!strcmp(var,"host_name")){
-					host_name=strdup(val);
+					host_name=mt_strdup(val);
 					temp_host=find_host(host_name);
 				        }
 				else if(temp_host!=NULL){
@@ -715,10 +715,10 @@
 								temp_buffer2[sizeof(temp_buffer2)-1]='\x0';
 								temp_ptr=my_strtok(temp_buffer2,"!");
 								temp_command=find_command(temp_ptr);
-								temp_ptr=strdup(val);
+								temp_ptr=mt_strdup(val);
 
 								if(temp_command!=NULL && temp_ptr!=NULL){
-									free(temp_host->host_check_command);
+									mt_free(temp_host->host_check_command);
 									temp_host->host_check_command=temp_ptr;
 								        }
 							        }
@@ -731,10 +731,10 @@
 								temp_buffer2[sizeof(temp_buffer2)-1]='\x0';
 								temp_ptr=my_strtok(temp_buffer2,"!");
 								temp_command=find_command(temp_ptr);
-								temp_ptr=strdup(val);
+								temp_ptr=mt_strdup(val);
 
 								if(temp_command!=NULL && temp_ptr!=NULL){
-									free(temp_host->event_handler);
+									mt_free(temp_host->event_handler);
 									temp_host->event_handler=temp_ptr;
 								        }
 							        }
@@ -760,11 +760,11 @@
 
 			case XRDDEFAULT_SERVICE_DATA:
 				if(!strcmp(var,"host_name")){
-					host_name=strdup(val);
+					host_name=mt_strdup(val);
 					temp_service=find_service(host_name,service_description);
 				        }
 				else if(!strcmp(var,"service_description")){
-					service_description=strdup(val);
+					service_description=mt_strdup(val);
 					temp_service=find_service(host_name,service_description);
 				        }
 				else if(temp_service!=NULL){
@@ -878,10 +878,10 @@
 								temp_buffer2[sizeof(temp_buffer2)-1]='\x0';
 								temp_ptr=my_strtok(temp_buffer2,"!");
 								temp_command=find_command(temp_ptr);
-								temp_ptr=strdup(val);
+								temp_ptr=mt_strdup(val);
 
 								if(temp_command!=NULL && temp_ptr!=NULL){
-									free(temp_service->service_check_command);
+									mt_free(temp_service->service_check_command);
 									temp_service->service_check_command=temp_ptr;
 								        }
 							        }
@@ -894,10 +894,10 @@
 								temp_buffer2[sizeof(temp_buffer2)-1]='\x0';
 								temp_ptr=my_strtok(temp_buffer2,"!");
 								temp_command=find_command(temp_ptr);
-								temp_ptr=strdup(val);
+								temp_ptr=mt_strdup(val);
 
 								if(temp_command!=NULL && temp_ptr!=NULL){
-									free(temp_service->event_handler);
+									mt_free(temp_service->event_handler);
 									temp_service->event_handler=temp_ptr;
 								        }
 							        }
@@ -932,7 +932,7 @@
 	        }
 
 	/* free memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 #ifdef DEBUG0
diff -urN /home/exon/Nagios/xdata/xsddefault.c ./xdata/xsddefault.c
--- /home/exon/Nagios/xdata/xsddefault.c	2004-11-05 15:18:53.000000000 +0100
+++ ./xdata/xsddefault.c	2004-12-01 22:48:42.000000000 +0100
@@ -139,7 +139,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -167,7 +167,7 @@
 			while(1){
 
 				/* free memory */
-				free(input2);
+				mt_free(input2);
 
 				/* read the next line */
 				if((input2=mmap_fgets(thefile2))==NULL)
@@ -183,7 +183,7 @@
 			        }
 
 			/* free memory and close the file */
-			free(input2);
+			mt_free(input2);
 			mmap_fclose(thefile2);
 		        }
 #endif
@@ -195,7 +195,7 @@
 	        }
 
 	/* free memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	/* we didn't find the status log name */
@@ -209,8 +209,8 @@
 #ifdef NSCORE
 	/* save the status file macro */
 	if(macro_x[MACRO_STATUSDATAFILE]!=NULL)
-		free(macro_x[MACRO_STATUSDATAFILE]);
-	macro_x[MACRO_STATUSDATAFILE]=(char *)strdup(xsddefault_status_log);
+		mt_free(macro_x[MACRO_STATUSDATAFILE]);
+	macro_x[MACRO_STATUSDATAFILE]=(char *)mt_strdup(xsddefault_status_log);
 	if(macro_x[MACRO_STATUSDATAFILE]!=NULL)
 		strip(macro_x[MACRO_STATUSDATAFILE]);
 #endif
@@ -509,7 +509,7 @@
 	while(1){
 
 		/* free memory */
-		free(input);
+		mt_free(input);
 
 		/* read the next line */
 		if((input=mmap_fgets(thefile))==NULL)
@@ -527,7 +527,7 @@
 			data_type=XSDDEFAULT_PROGRAM_DATA;
 		else if(!strcmp(input,"host {")){
 			data_type=XSDDEFAULT_HOST_DATA;
-			temp_hoststatus=(hoststatus *)malloc(sizeof(hoststatus));
+			temp_hoststatus=(hoststatus *)mt_malloc(sizeof(hoststatus));
 			if(temp_hoststatus){
 				temp_hoststatus->host_name=NULL;
 				temp_hoststatus->plugin_output=NULL;
@@ -536,7 +536,7 @@
 		        }
 		else if(!strcmp(input,"service {")){
 			data_type=XSDDEFAULT_SERVICE_DATA;
-			temp_servicestatus=(servicestatus *)malloc(sizeof(servicestatus));
+			temp_servicestatus=(servicestatus *)mt_malloc(sizeof(servicestatus));
 			if(temp_servicestatus){
 				temp_servicestatus->host_name=NULL;
 				temp_servicestatus->description=NULL;
@@ -628,7 +628,7 @@
 				/* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */
 				if(temp_hoststatus!=NULL){
 					if(!strcmp(var,"host_name"))
-						temp_hoststatus->host_name=strdup(val);
+						temp_hoststatus->host_name=mt_strdup(val);
 					else if(!strcmp(var,"has_been_checked"))
 						temp_hoststatus->has_been_checked=(atoi(val)>0)?TRUE:FALSE;
 					else if(!strcmp(var,"should_be_scheduled"))
@@ -642,9 +642,9 @@
 					else if(!strcmp(var,"last_hard_state"))
 						temp_hoststatus->last_hard_state=atoi(val);
 					else if(!strcmp(var,"plugin_output"))
-						temp_hoststatus->plugin_output=strdup(val);
+						temp_hoststatus->plugin_output=mt_strdup(val);
 					else if(!strcmp(var,"performance_data"))
-						temp_hoststatus->perf_data=strdup(val);
+						temp_hoststatus->perf_data=mt_strdup(val);
 					else if(!strcmp(var,"current_attempt"))
 						temp_hoststatus->current_attempt=atoi(val);
 					else if(!strcmp(var,"max_attempts"))
@@ -720,9 +720,9 @@
 				/* NOTE: some vars are not read, as they are not used by the CGIs (modified attributes, event handler commands, etc.) */
 				if(temp_servicestatus!=NULL){
 					if(!strcmp(var,"host_name"))
-						temp_servicestatus->host_name=strdup(val);
+						temp_servicestatus->host_name=mt_strdup(val);
 					else if(!strcmp(var,"service_description"))
-						temp_servicestatus->description=strdup(val);
+						temp_servicestatus->description=mt_strdup(val);
 					else if(!strcmp(var,"has_been_checked"))
 						temp_servicestatus->has_been_checked=(atoi(val)>0)?TRUE:FALSE;
 					else if(!strcmp(var,"should_be_scheduled"))
@@ -754,9 +754,9 @@
 					else if(!strcmp(var,"last_time_critical"))
 						temp_servicestatus->last_time_critical=strtoul(val,NULL,10);
 					else if(!strcmp(var,"plugin_output"))
-						temp_servicestatus->plugin_output=strdup(val);
+						temp_servicestatus->plugin_output=mt_strdup(val);
 					else if(!strcmp(var,"performance_data"))
-						temp_servicestatus->perf_data=strdup(val);
+						temp_servicestatus->perf_data=mt_strdup(val);
 					else if(!strcmp(var,"last_check"))
 						temp_servicestatus->last_check=strtoul(val,NULL,10);
 					else if(!strcmp(var,"next_check"))
@@ -818,7 +818,7 @@
 	        }
 
 	/* free memory and close the file */
-	free(input);
+	mt_free(input);
 	mmap_fclose(thefile);
 
 	return OK;
