TIME: Set Allocated Pointers to NULL after free()'d;

This commit is contained in:
lwvmobile 2024-04-25 18:22:28 -04:00
parent 7bcd29abec
commit db036f4dfc
10 changed files with 182 additions and 56 deletions

View File

@ -13,7 +13,7 @@
//processing voice and/or data on both BS slots (channels) simultaneously
void dmrBS (dsd_opts * opts, dsd_state * state)
{
char * timestr;
char * timestr = NULL;
int i, dibit;
char ambe_fr[4][24];
@ -549,14 +549,12 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
ncursesPrinter(opts, state);
}
//both here and at bottom SHOULD be okay with the NULL check, if not, disable this one
//
if (timestr != NULL)
{
//debug
// fprintf (stderr, " FREE: 1; ");
free (timestr);
timestr = NULL;
}
// else fprintf (stderr, " NO FREE: 1; ");
} // while loop
@ -604,14 +602,12 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
}
//second free
//
if (timestr != NULL)
{
//debug
// fprintf (stderr, " FREE: 2; ");
free (timestr);
}
// else fprintf (stderr, " NO FREE: 2; ");
{
free (timestr);
timestr = NULL;
}
}
@ -923,6 +919,10 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
dmr_reset_blocks (opts, state);
}
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
}

View File

@ -374,7 +374,11 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
state->dmr_ms_rc = 0;
state->directmode = 0; //flag off
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
}
@ -618,7 +622,11 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
//errors due to skipping other slot
// cach_err = dmr_cach (opts, state, cachdata);
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
skipDibit (opts, state, 144); //skip to next TDMA slot
dmrMS (opts, state); //bootstrap into full TDMA frame
@ -689,6 +697,10 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
state->dmr_stereo_payload[i+66] = 1; ////set to one so first frame will fail intentionally instead of zero fill
}
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
}

View File

@ -260,8 +260,16 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DM
if (!source) fprintf (pFile, "%08lld\t", state->dmr_lrrp_source[state->currentslot]); //source address from data header
if (source) fprintf (pFile, "%08d\t", source); //add source form decoded audio if available, else its from the header
if (timestr != NULL) free (timestr);
if (datestr != NULL) free (datestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
}
if (pot_report)

View File

@ -409,8 +409,16 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state)
fprintf (opts->mbe_out_f, "%s", ext);
fflush (opts->mbe_out_f);
if (timestr != NULL) free (timestr);
if (datestr != NULL) free (datestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
}
void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
@ -463,8 +471,16 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
fprintf (opts->mbe_out_fR, "%s", ext);
fflush (opts->mbe_out_fR);
if (timestr != NULL) free (timestr);
if (datestr != NULL) free (datestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
}
void openWavOutFile (dsd_opts * opts, dsd_state * state)

View File

@ -36,7 +36,11 @@ printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset,
if (opts->verbose > 2)
//fprintf (stderr,"g: %f ", state->aout_gain);
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
}

View File

@ -135,8 +135,16 @@ void lip_protocol_decoder (dsd_opts * opts, dsd_state * state, uint8_t * input)
fprintf (pFile, "\n");
fclose (pFile);
if (datestr != NULL) free (datestr);
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
}
@ -246,8 +254,16 @@ void nmea_iec_61162_1 (dsd_opts * opts, dsd_state * state, uint8_t * input, uint
fprintf (pFile, "\n");
fclose (pFile);
if (datestr != NULL) free (datestr);
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
}
@ -371,8 +387,16 @@ void nmea_harris (dsd_opts * opts, dsd_state * state, uint8_t * input, uint32_t
fprintf (pFile, "\n");
fclose (pFile);
if (datestr != NULL) free (datestr);
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
}
@ -501,8 +525,16 @@ void harris_gps(dsd_opts * opts, dsd_state * state, int slot, uint8_t * input)
fprintf (pFile, "\n");
fclose (pFile);
if (datestr != NULL) free (datestr);
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
}
@ -714,8 +746,16 @@ void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[])
fprintf (pFile, "\n");
fclose (pFile);
if (datestr != NULL) free (datestr);
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
}

View File

@ -654,11 +654,19 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state)
print_menuc(test_win, highlightc);
if (choicec == 2)
{
char * timestr = getTime();
char * datestr = getDate();
char * timestr = getTime();
char * datestr = getDate();
sprintf (opts->wav_out_file, "%s %s DSD-FME-DECODED.wav", datestr, timestr);
if (timestr != NULL) free (timestr);
if (datestr != NULL) free (datestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
openWavOutFile (opts, state);
}
if (choicec == 3)
@ -1954,8 +1962,8 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
int c = 0;
//for filenames (no colons, etc)
char * timestr = getTime();
char * datestr = getDate();
char * timestr = getTime();
char * datestr = getDate();
//NOTE: Any times associates with call history are stored
//in the array and need to be set by passing those values into
@ -3813,8 +3821,16 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
printw ("%s ", datestrCH);
printw ("%s ", timestrCH);
if (datestrCH != NULL) free (datestrCH);
if (timestrCH != NULL) free (timestrCH);
if (datestrCH != NULL)
{
free (datestrCH);
datestrCH = NULL;
}
if (timestrCH != NULL)
{
free (timestrCH);
timestrCH = NULL;
}
if (lls == 28 || lls == 29)
{
@ -3891,8 +3907,16 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
printw ("%s ", datestrCHE);
printw ("%s ", timestrCHE);
if (datestrCHE != NULL) free (datestrCHE);
if (timestrCHE != NULL) free (timestrCHE);
if (datestrCHE != NULL)
{
free (datestrCHE);
datestrCHE = NULL;
}
if (timestrCHE != NULL)
{
free (timestrCHE);
timestrCHE = NULL;
}
printw ("LCN [%2lld] ", call_matrix[j][1]);
if (state->ea_mode == 1)
@ -4847,8 +4871,16 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
//allocated memory pointer needs to be free'd
if (timestr != NULL) free (timestr);
if (datestr != NULL) free (datestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} //end ncursesPrinter

View File

@ -14,7 +14,7 @@
//get HHmmss timestamp no colon (file operations)
char * getTime()
{
char * curr = (char *) malloc(7);
char * curr = calloc(7, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr,"%02d%02d%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
@ -24,7 +24,7 @@ char * getTime()
//get HH:mm:ss timestamp with colon (Sync/Console Display)
char * getTimeC()
{
char * curr = (char *) malloc(9);
char * curr = calloc(9, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
@ -34,7 +34,7 @@ char * getTimeC()
//get HH:mm:ss timestamp with colon (Ncurses Call History)
char * getTimeN(time_t t)
{
char * curr = (char *) malloc(9);
char * curr = calloc(9, sizeof(char));
struct tm * ptm = localtime(& t);
sprintf(curr, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
return curr;
@ -43,7 +43,7 @@ char * getTimeN(time_t t)
//get YYYYMMDD without hyphen (file operations)
char * getDate()
{
char * curr = (char *) malloc(25);
char * curr = calloc(25, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr,"%04d%02d%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
@ -53,7 +53,7 @@ char * getDate()
//get YYYY-MM-DD with hyphen (Sync/Console Display)
char * getDateH()
{
char * curr = (char *) malloc(27);
char * curr = calloc(27, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr, "%04d-%02d-%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
@ -63,7 +63,7 @@ char * getDateH()
//get YYYY-MM-DD with hyphen (Ncurses Call History)
char * getDateN(time_t t)
{
char * curr = (char *) malloc(27);
char * curr = calloc(27, sizeof(char));
struct tm * ptm = localtime(& t);
sprintf(curr, "%04d-%02d-%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
return curr;

View File

@ -440,8 +440,8 @@ void edacs(dsd_opts * opts, dsd_state * state)
state->edacs_f_mask = (1 << state->edacs_f_bits) - 1;
state->edacs_s_mask = (1 << state->edacs_s_bits) - 1;
char * timestr; //add timestr here, so we can assign it and also free it to prevent memory leak
char * datestr;
char * timestr = NULL;
char * datestr = NULL;
timestr = getTime();
datestr = getDate();
@ -2135,8 +2135,17 @@ void edacs(dsd_opts * opts, dsd_state * state)
}
if (timestr != NULL) free (timestr);
if (datestr != NULL) free (datestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
fprintf (stderr, "\n");
}

View File

@ -874,7 +874,12 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
fprintf (stderr,"%s ", timestr);
fprintf (stderr, " P25p2 ");
if (timestr != NULL) free (timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (state->currentslot == 0 && duid_decoded != 3 && duid_decoded != 12 && duid_decoded != 13 && duid_decoded != 4)
{