Page 1 of 1

[Nagios-devel] memtracker

Posted: Thu Dec 02, 2004 3:33 pm
by Guest
This is a multi-part message in MIME format.
--------------010101000401060700000902
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Ahoy.

I've finished the memory tracker. It tracks strdup(), malloc(),
realloc() and free() calls, and just keeps tabs on what's used and what
isn't.

Apply the attached patch (patch -p1), ./configure and make nagios
The output ends up in /tmp/nagios.leak

The main point is to let nagios run a couple of times through its hopps,
force a sigsegv so it dumps core and then use the (preferrably parsed)
leak output to find name and location of the variables that are never freed.

It's conditional to MEMLEAK_DEBUG being defined, so it can be kept
around without affecting anything on production systems.

--
Andreas Ericsson [email protected]
OP5 AB www.op5.se
Lead Developer

--------------010101000401060700000902
Content-Type: text/plain;
name="nagios-memtracker.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="nagios-memtracker.diff"

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/

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]