summaryrefslogtreecommitdiff
path: root/fxotune.c
diff options
context:
space:
mode:
authorrussell <russell@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-08-15 22:06:13 +0000
committerrussell <russell@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2006-08-15 22:06:13 +0000
commitb7e384475ac03b7e236113847927e7b0edeced77 (patch)
tree4914201e23963cafaada295866bc3c44bf32c9b0 /fxotune.c
parented669308b81c3f0d0c892dc07b066d9ccec83090 (diff)
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) git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.2@1315 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'fxotune.c')
-rw-r--r--fxotune.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/fxotune.c b/fxotune.c
index 312ecca..c5db4d1 100644
--- a/fxotune.c
+++ b/fxotune.c
@@ -49,6 +49,7 @@ static char *usage =
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 @@ static int acim_tune(int whichzap, char *dialstr)
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 @@ static int acim_tune(int whichzap, char *dialstr)
/* 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);
}