From ffa8b053d7007a53350dcced8f6953cb1203c4a3 Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Tue, 30 Jan 2024 23:43:32 -0500 Subject: [PATCH] Fix minor memory leak on timestr; --- .gitignore | 1 + src/dsd_file.c | 10 ++++++++-- src/dsd_ncurses.c | 8 +++++++- src/edacs-fme.c | 9 ++++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 67d5d1c..19e7350 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ examples *.bin *.ans *.patch +*.zip \ No newline at end of file diff --git a/src/dsd_file.c b/src/dsd_file.c index 2e7002f..67607e5 100644 --- a/src/dsd_file.c +++ b/src/dsd_file.c @@ -396,6 +396,8 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state) int i, j; char ext[5]; + char * timestr; //add timestr here, so we can assign it and also free it to prevent memory leak + timestr = getTimeF(); //phase 1 and provoice if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) ) @@ -421,7 +423,7 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state) state->tgcount = 0; - sprintf (opts->mbe_out_file, "%s %s S1%s", getDateF(), getTimeF(), ext); + sprintf (opts->mbe_out_file, "%s %s S1%s", getDateF(), timestr, ext); sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_file); @@ -436,6 +438,7 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state) fprintf (opts->mbe_out_f, "%s", ext); fflush (opts->mbe_out_f); + free (timestr); //free allocated memory to prevent memory leak } void openMbeOutFileR (dsd_opts * opts, dsd_state * state) @@ -443,6 +446,8 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state) int i, j; char ext[5]; + char * timestr; //add timestr here, so we can assign it and also free it to prevent memory leak + timestr = getTimeF(); //phase 1 and provoice if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) ) @@ -468,7 +473,7 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state) state->tgcount = 0; - sprintf (opts->mbe_out_fileR, "%s %s S2%s", getDateF(), getTimeF(), ext); + sprintf (opts->mbe_out_fileR, "%s %s S2%s", getDateF(), timestr, ext); sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_fileR); @@ -483,6 +488,7 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state) fprintf (opts->mbe_out_fR, "%s", ext); fflush (opts->mbe_out_fR); + free (timestr); //free allocated memory to prevent memory leak } void openWavOutFile (dsd_opts * opts, dsd_state * state) diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index e094f07..7de3ffb 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -1853,7 +1853,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) //fix location of this statement to inside the if statement and add conditions if (opts->audio_in_type == 3) //open rtl input if it is the specified input method { - ncursesPrinter (opts, state); //run one rep to clear menu boxes out + // ncursesPrinter (opts, state); //not sure why this was placed here originally, but causes a double free core dump when calling free(timestr) #ifdef USE_RTLSDR if (opts->rtl_started == 0) { @@ -4353,6 +4353,12 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) //so probably just write a function to handle c input, and when c = certain values //needing an entry box, then stop all of those + //allocated memory pointer needs to be free'd each time + //if issues arise, just delete this line. + //TODO: Redo this in edacs and file, making a seperate char * timestr instead of calling GetTime + //directly from the sprintf command + free (timestr); + } //end ncursesPrinter void ncursesClose () diff --git a/src/edacs-fme.c b/src/edacs-fme.c index 8d19c4c..e9e404b 100644 --- a/src/edacs-fme.c +++ b/src/edacs-fme.c @@ -297,6 +297,9 @@ void edacs(dsd_opts * opts, dsd_state * state) unsigned int netcmd = 0xF3; //using for Networked Test UNUSED2(vcmd, idcmd); + char * timestr; //add timestr here, so we can assign it and also free it to prevent memory leak + timestr = getTimeE(); + state->edacs_vc_lcn = -1; //init on negative for ncurses and tuning int i; @@ -512,7 +515,7 @@ void edacs(dsd_opts * opts, dsd_state * state) //openwav file and do per call right here, should probably check as well to make sure we have a valid trunking method active (rigctl, rtl) if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) { - sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TG %d SRC %d.wav", getDateE(), getTimeE(), state->edacs_site_id, group, source); + sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TG %d SRC %d.wav", getDateE(), timestr, state->edacs_site_id, group, source); openWavOutFile (opts, state); // openWavOutFile48k (opts, state); //debug for testing analog wav only } @@ -671,7 +674,7 @@ void edacs(dsd_opts * opts, dsd_state * state) //openwav file and do per call right here if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) { - sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld AFS %02d-%03d - %03d.wav", getDateE(), getTimeE(), state->edacs_site_id, a, fs, afs); + sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld AFS %02d-%03d - %03d.wav", getDateE(), timestr, state->edacs_site_id, a, fs, afs); if (command == 0xEF) openWavOutFile (opts, state); //digital if (command == 0xEE) openWavOutFile48k (opts, state); //analog at 48k } @@ -722,7 +725,7 @@ void edacs(dsd_opts * opts, dsd_state * state) } ENDPV: - + free (timestr); //free allocated memory to prevent memory leak fprintf (stderr, "\n"); }