[asterisk-commits] tilghman: branch 1.4 r187300 - in /branches/1.4: agi/ build_tools/ include/ m...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 8 23:31:50 CDT 2009


Author: tilghman
Date: Wed Apr  8 23:31:38 2009
New Revision: 187300

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=187300
Log:
Add debugging mode for diagnosing file descriptor leaks.
(Related to issue #14625)

Modified:
    branches/1.4/agi/Makefile
    branches/1.4/build_tools/cflags.xml
    branches/1.4/include/asterisk.h
    branches/1.4/main/Makefile
    branches/1.4/main/asterisk.c
    branches/1.4/main/file.c
    branches/1.4/utils/Makefile

Modified: branches/1.4/agi/Makefile
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/agi/Makefile?view=diff&rev=187300&r1=187299&r2=187300
==============================================================================
--- branches/1.4/agi/Makefile (original)
+++ branches/1.4/agi/Makefile Wed Apr  8 23:31:38 2009
@@ -20,6 +20,8 @@
 endif
 
 include $(ASTTOPDIR)/Makefile.rules
+
+ASTCFLAGS+=-DSTANDALONE
 
 all: $(AGIS)
 

Modified: branches/1.4/build_tools/cflags.xml
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/build_tools/cflags.xml?view=diff&rev=187300&r1=187299&r2=187300
==============================================================================
--- branches/1.4/build_tools/cflags.xml (original)
+++ branches/1.4/build_tools/cflags.xml Wed Apr  8 23:31:38 2009
@@ -4,6 +4,8 @@
 		<member name="DEBUG_CHANNEL_LOCKS" displayname="Debug Channel Locking">
 		</member>
 		<member name="DEBUG_THREADS" displayname="Enable Thread Debugging">
+		</member>
+		<member name="DEBUG_FD_LEAKS" displayname="Enable File Descriptor Leak Detection">
 		</member>
 		<member name="LOW_MEMORY" displayname="Optimize for Low Memory Usage">
 		</member>

Modified: branches/1.4/include/asterisk.h
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/include/asterisk.h?view=diff&rev=187300&r1=187299&r2=187300
==============================================================================
--- branches/1.4/include/asterisk.h (original)
+++ branches/1.4/include/asterisk.h Wed Apr  8 23:31:38 2009
@@ -34,6 +34,34 @@
 #define DEFAULT_SAMPLES_PER_MS  ((DEFAULT_SAMPLE_RATE)/1000)
 #define	setpriority	__PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__
 #define	sched_setscheduler	__PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__
+
+#if defined(DEBUG_FD_LEAKS) && !defined(STANDALONE) && !defined(STANDALONE_AEL)
+/* These includes are all about ordering */
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#define	open(a,...)	__ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)
+#define pipe(a)	__ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+#define socket(a,b,c)	__ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+#define close(a)	__ast_fdleak_close(a)
+#define	fopen(a,b)	__ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+#define	fclose(a)	__ast_fdleak_fclose(a)
+#define	dup2(a,b)	__ast_fdleak_dup2(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+#define dup(a)	__ast_fdleak_dup(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)
+
+int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);
+int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);
+int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);
+int __ast_fdleak_close(int fd);
+FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);
+int __ast_fdleak_fclose(FILE *ptr);
+int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func);
+int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func);
+#endif
 
 /* provided in asterisk.c */
 extern char ast_config_AST_CONFIG_DIR[PATH_MAX];
@@ -73,6 +101,7 @@
 void threadstorage_init(void);			/*!< Provided by threadstorage.c */
 int astobj2_init(void);				/*! Provided by astobj2.c */
 void ast_autoservice_init(void);    /*!< Provided by autoservice.c */
+int ast_fd_init(void);				/*!< Provided by astfd.c */
 
 /* Many headers need 'ast_channel' to be defined */
 struct ast_channel;

Modified: branches/1.4/main/Makefile
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/Makefile?view=diff&rev=187300&r1=187299&r2=187300
==============================================================================
--- branches/1.4/main/Makefile (original)
+++ branches/1.4/main/Makefile Wed Apr  8 23:31:38 2009
@@ -22,7 +22,7 @@
 	ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
 	cdr.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
 	dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
-	astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
+	astmm.o astfd.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
 	utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
 	netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
 	cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \

Modified: branches/1.4/main/asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/asterisk.c?view=diff&rev=187300&r1=187299&r2=187300
==============================================================================
--- branches/1.4/main/asterisk.c (original)
+++ branches/1.4/main/asterisk.c Wed Apr  8 23:31:38 2009
@@ -2732,6 +2732,7 @@
 	ast_builtins_init();
 	ast_utils_init();
 	tdd_init();
+	ast_fd_init();
 
 	if (getenv("HOME")) 
 		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));

Modified: branches/1.4/main/file.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/file.c?view=diff&rev=187300&r1=187299&r2=187300
==============================================================================
--- branches/1.4/main/file.c (original)
+++ branches/1.4/main/file.c Wed Apr  8 23:31:38 2009
@@ -332,8 +332,10 @@
 		free(f->filename);
 	if (f->realfilename)
 		free(f->realfilename);
-	if (f->fmt->close)
-		f->fmt->close(f);
+	if (f->fmt->close) {
+		void (*closefn)(struct ast_filestream *) = f->fmt->close;
+		closefn(f);
+	}
 	if (f->f)
 		fclose(f->f);
 	if (f->vfs)
@@ -371,8 +373,9 @@
 {
 	struct ast_format *f = s->fmt;
 	int ret = -1;
-
-	if (mode == WRAP_OPEN && f->open && f->open(s))
+	int (*openfn)(struct ast_filestream *s);
+
+	if (mode == WRAP_OPEN && (openfn = f->open) && openfn(s))
                 ast_log(LOG_WARNING, "Unable to open format %s\n", f->name);
 	else if (mode == WRAP_REWRITE && f->rewrite && f->rewrite(s, comment))
                 ast_log(LOG_WARNING, "Unable to rewrite format %s\n", f->name);

Modified: branches/1.4/utils/Makefile
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/utils/Makefile?view=diff&rev=187300&r1=187299&r2=187300
==============================================================================
--- branches/1.4/utils/Makefile (original)
+++ branches/1.4/utils/Makefile Wed Apr  8 23:31:38 2009
@@ -75,7 +75,7 @@
 
 astman: astman.o md5.o
 astman: LIBS+=$(NEWT_LIB)
-astman.o: ASTCFLAGS+=-DNO_MALLOC_DEBUG
+astman.o: ASTCFLAGS+=-DNO_MALLOC_DEBUG -DSTANDALONE
 
 stereorize: stereorize.o frame.o
 stereorize: LIBS+=-lm




More information about the asterisk-commits mailing list