[zaptel-commits] russell: branch 1.2 r1315 - /branches/1.2/fxotune.c

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Tue Aug 15 15:06:13 MST 2006


Author: russell
Date: Tue Aug 15 17:06:13 2006
New Revision: 1315

URL: http://svn.digium.com/view/zaptel?rev=1315&view=rev
Log:
Ensure that fopen() is only called once for the debug output file to prevent
excessive file descriptor leakage when this function is called many times in
a loop.  (issue #7203)

Modified:
    branches/1.2/fxotune.c

Modified: branches/1.2/fxotune.c
URL: http://svn.digium.com/view/zaptel/branches/1.2/fxotune.c?rev=1315&r1=1314&r2=1315&view=diff
==============================================================================
--- branches/1.2/fxotune.c (original)
+++ branches/1.2/fxotune.c Tue Aug 15 17:06:13 2006
@@ -49,6 +49,7 @@
 static short outbuf[TEST_DURATION];
 static int debug = 0;
 
+static FILE *outfile = NULL;
 
 /* Generates a tone of hz frequency.  Index is the current sample
  * to begenerated.  For a normal waveform you need to increment
@@ -128,13 +129,10 @@
 	struct wctdm_echo_coefs coefs;
 	short inbuf[BUFFER_LENGTH]; 
 	int lowest = 0;
-	FILE *outfile = NULL;
 	float acim_results[16];
 
-
-	if (debug) {
-		outfile = fopen("fxotune.vals", "w");
-		if (!outfile) {
+	if (debug && !outfile) {
+		if (!(outfile = fopen("fxotune.vals", "w"))) {
 			fprintf(stdout, "Cannot create fxotune.vals\n");
 			return -1;
 		}
@@ -243,7 +241,8 @@
 			/* calculate power of response */
 			
 			freq_results[(freq/200)-1] = power_of(inbuf+SKIP_BYTES, BUFFER_LENGTH-SKIP_BYTES, 1);
-			if (debug) fprintf(outfile, "%d,%d,%f\n", acim, freq, freq_results[(freq/200)-1]);
+			if (debug) 
+				fprintf(outfile, "%d,%d,%f\n", acim, freq, freq_results[(freq/200)-1]);
 		}
 		acim_results[acim] = power_of(freq_results, 15, 0);
 	}



More information about the zaptel-commits mailing list