Fix minor memory leak on timestr;

This commit is contained in:
lwvmobile
2024-01-30 23:43:32 -05:00
parent c39ddbc7a7
commit ffa8b053d7
4 changed files with 22 additions and 6 deletions

1
.gitignore vendored
View File

@@ -8,3 +8,4 @@ examples
*.bin *.bin
*.ans *.ans
*.patch *.patch
*.zip

View File

@@ -396,6 +396,8 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state)
int i, j; int i, j;
char ext[5]; 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 //phase 1 and provoice
if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) ) 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; 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); 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); fprintf (opts->mbe_out_f, "%s", ext);
fflush (opts->mbe_out_f); fflush (opts->mbe_out_f);
free (timestr); //free allocated memory to prevent memory leak
} }
void openMbeOutFileR (dsd_opts * opts, dsd_state * state) void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
@@ -443,6 +446,8 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
int i, j; int i, j;
char ext[5]; 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 //phase 1 and provoice
if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) ) 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; 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); 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); fprintf (opts->mbe_out_fR, "%s", ext);
fflush (opts->mbe_out_fR); fflush (opts->mbe_out_fR);
free (timestr); //free allocated memory to prevent memory leak
} }
void openWavOutFile (dsd_opts * opts, dsd_state * state) void openWavOutFile (dsd_opts * opts, dsd_state * state)

View File

@@ -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 //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 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 #ifdef USE_RTLSDR
if (opts->rtl_started == 0) 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 //so probably just write a function to handle c input, and when c = certain values
//needing an entry box, then stop all of those //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 } //end ncursesPrinter
void ncursesClose () void ncursesClose ()

View File

@@ -297,6 +297,9 @@ void edacs(dsd_opts * opts, dsd_state * state)
unsigned int netcmd = 0xF3; //using for Networked Test unsigned int netcmd = 0xF3; //using for Networked Test
UNUSED2(vcmd, idcmd); 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 state->edacs_vc_lcn = -1; //init on negative for ncurses and tuning
int i; 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) //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)) 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); openWavOutFile (opts, state);
// openWavOutFile48k (opts, state); //debug for testing analog wav only // 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 //openwav file and do per call right here
if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) 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 == 0xEF) openWavOutFile (opts, state); //digital
if (command == 0xEE) openWavOutFile48k (opts, state); //analog at 48k if (command == 0xEE) openWavOutFile48k (opts, state); //analog at 48k
} }
@@ -722,7 +725,7 @@ void edacs(dsd_opts * opts, dsd_state * state)
} }
ENDPV: ENDPV:
free (timestr); //free allocated memory to prevent memory leak
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }