From c370e90f86d16d7d8c1669316c8ee2d884e95ef0 Mon Sep 17 00:00:00 2001 From: russell Date: Tue, 15 Aug 2006 22:14:21 +0000 Subject: Merged revisions 1315 via svnmerge from https://origsvn.digium.com/svn/zaptel/branches/1.2 ........ r1315 | russell | 2006-08-15 18:06:13 -0400 (Tue, 15 Aug 2006) | 4 lines 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/trunk@1316 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- fxotune.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fxotune.c b/fxotune.c index a36be1a..7abfc4b 100644 --- a/fxotune.c +++ b/fxotune.c @@ -86,6 +86,8 @@ struct silence_info{ static short outbuf[TEST_DURATION]; static int debug = 0; +static FILE *debugoutfile = NULL; + /** * Makes sure that the line is clear. * Right now, we do this by relying on the user to specify how long after dialing the @@ -262,7 +264,6 @@ static int maptone(int whichzap, int freq, char *dialstr, int delayuntilsilence) short inbuf[TEST_DURATION]; /* changed from BUFFER_LENGTH - this buffer is for short values, so it should be allocated using the length of the test */ FILE *outfile = NULL; - outfile = fopen("fxotune_dump.vals", "w"); if (!outfile) { fprintf(stdout, "Cannot create fxotune_dump.vals\n"); @@ -392,12 +393,9 @@ static int acim_tune2(int whichzap, int freq, char *dialstr, int delayuntilsilen struct zt_bufferinfo bi; short inbuf[TEST_DURATION]; - FILE *outfile = NULL; - - if (debug) { - outfile = fopen("fxotune.vals", "w"); - if (!outfile) { + if (debug && !debugoutfile) { + if (!(debugoutfile = fopen("fxotune.vals", "w"))) { fprintf(stdout, "Cannot create fxotune.vals\n"); return -1; } @@ -516,7 +514,7 @@ static int acim_tune2(int whichzap, int freq, char *dialstr, int delayuntilsilen echo ); - fprintf(outfile, "%s\n", result); + fprintf(debugoutfile, "%s\n", result); if (debug > 1) fprintf(stdout, "%s\n", result); } -- cgit v1.2.3