diff --git a/src/dmr_bs.c b/src/dmr_bs.c index 174ba0c..8d2775b 100644 --- a/src/dmr_bs.c +++ b/src/dmr_bs.c @@ -549,6 +549,15 @@ 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); + } + // else fprintf (stderr, " NO FREE: 1; "); + } // while loop END: @@ -595,7 +604,14 @@ void dmrBS (dsd_opts * opts, dsd_state * state) } - free (timestr); + //second free + if (timestr != NULL) + { + //debug + // fprintf (stderr, " FREE: 2; "); + free (timestr); + } +// else fprintf (stderr, " NO FREE: 2; "); } @@ -907,6 +923,6 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) dmr_reset_blocks (opts, state); } - free (timestr); + if (timestr != NULL) free (timestr); } diff --git a/src/dmr_ms.c b/src/dmr_ms.c index f527563..dacba16 100644 --- a/src/dmr_ms.c +++ b/src/dmr_ms.c @@ -374,7 +374,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state) state->dmr_ms_rc = 0; state->directmode = 0; //flag off - free(timestr); + if (timestr != NULL) free (timestr); } @@ -618,7 +618,7 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state) //errors due to skipping other slot // cach_err = dmr_cach (opts, state, cachdata); - free (timestr); + if (timestr != NULL) free (timestr); skipDibit (opts, state, 144); //skip to next TDMA slot dmrMS (opts, state); //bootstrap into full TDMA frame @@ -689,6 +689,6 @@ 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 } - free (timestr); + if (timestr != NULL) free (timestr); } diff --git a/src/dmr_pdu.c b/src/dmr_pdu.c index a836657..38bc16e 100644 --- a/src/dmr_pdu.c +++ b/src/dmr_pdu.c @@ -260,8 +260,8 @@ 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 - free (timestr); - free (datestr); + if (timestr != NULL) free (timestr); + if (datestr != NULL) free (datestr); } if (pot_report) diff --git a/src/dsd_file.c b/src/dsd_file.c index 21bda4c..32c09fa 100644 --- a/src/dsd_file.c +++ b/src/dsd_file.c @@ -409,8 +409,8 @@ 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 - free (datestr); + if (timestr != NULL) free (timestr); + if (datestr != NULL) free (datestr); } void openMbeOutFileR (dsd_opts * opts, dsd_state * state) @@ -463,8 +463,8 @@ 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 - free (datestr); + if (timestr != NULL) free (timestr); + if (datestr != NULL) free (datestr); } void openWavOutFile (dsd_opts * opts, dsd_state * state) diff --git a/src/dsd_frame_sync.c b/src/dsd_frame_sync.c index d9245e8..924469c 100644 --- a/src/dsd_frame_sync.c +++ b/src/dsd_frame_sync.c @@ -22,26 +22,21 @@ void printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset, char *modulation) { UNUSED3(state, offset, modulation); + char * timestr = getTimeC(); if (opts->verbose > 0) - { - fprintf (stderr,"%s ", timestr); - fprintf (stderr,"Sync: %s ", frametype); - } + { + fprintf (stderr,"%s ", timestr); + fprintf (stderr,"Sync: %s ", frametype); + } if (opts->verbose > 2) - { - //fprintf (stderr,"o: %4i ", offset); - } + //fprintf (stderr,"o: %4i ", offset); if (opts->verbose > 1) - { - //fprintf (stderr,"mod: %s ", modulation); - } + //fprintf (stderr,"mod: %s ", modulation); if (opts->verbose > 2) - { - //fprintf (stderr,"g: %f ", state->aout_gain); - } + //fprintf (stderr,"g: %f ", state->aout_gain); - free (timestr); + if (timestr != NULL) free (timestr); } diff --git a/src/dsd_gps.c b/src/dsd_gps.c index ea3afd1..7a6b4d9 100644 --- a/src/dsd_gps.c +++ b/src/dsd_gps.c @@ -135,8 +135,8 @@ void lip_protocol_decoder (dsd_opts * opts, dsd_state * state, uint8_t * input) fprintf (pFile, "\n"); fclose (pFile); - free (datestr); - free (timestr); + if (datestr != NULL) free (datestr); + if (timestr != NULL) free (timestr); } @@ -246,8 +246,8 @@ void nmea_iec_61162_1 (dsd_opts * opts, dsd_state * state, uint8_t * input, uint fprintf (pFile, "\n"); fclose (pFile); - free (datestr); - free (timestr); + if (datestr != NULL) free (datestr); + if (timestr != NULL) free (timestr); } @@ -371,8 +371,8 @@ void nmea_harris (dsd_opts * opts, dsd_state * state, uint8_t * input, uint32_t fprintf (pFile, "\n"); fclose (pFile); - free (datestr); - free (timestr); + if (datestr != NULL) free (datestr); + if (timestr != NULL) free (timestr); } @@ -501,8 +501,8 @@ void harris_gps(dsd_opts * opts, dsd_state * state, int slot, uint8_t * input) fprintf (pFile, "\n"); fclose (pFile); - free (datestr); - free (timestr); + if (datestr != NULL) free (datestr); + if (timestr != NULL) free (timestr); } @@ -714,8 +714,8 @@ void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) fprintf (pFile, "\n"); fclose (pFile); - free (datestr); - free (timestr); + if (datestr != NULL) free (datestr); + if (timestr != NULL) free (timestr); } diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index fe6dd54..193eb1b 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -3803,15 +3803,15 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) //only print if a valid time was assigned to the matrix, and not EDACS/PV, and source is not zero if ( ((time(NULL) - call_matrix[9-j][5]) < 999999) && call_matrix[9-j][0] != 14 && call_matrix[9-j][0] != 15 && call_matrix[9-j][0] != 37 && call_matrix[9-j][0] != 38 && call_matrix[9-j][2] != 0) // { - char * timeCH = getTimeN(call_matrix[9-j][5]); - char * dateCH = getDateN(call_matrix[9-j][5]); + char * timestrCH = getTimeN(call_matrix[9-j][5]); + char * datestrCH = getDateN(call_matrix[9-j][5]); printw ("| "); - printw ("%s ", dateCH); - printw ("%s ", timeCH); + printw ("%s ", datestrCH); + printw ("%s ", timestrCH); - free (dateCH); - free (timeCH); + if (datestrCH != NULL) free (datestrCH); + if (timestrCH != NULL) free (timestrCH); if (lls == 28 || lls == 29) { @@ -3882,14 +3882,14 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) if (call_matrix[j][2] != 0) { printw ("| "); - char * timeCHE = getTimeN(call_matrix[j][5]); - char * dateCHE = getDateN(call_matrix[j][5]); + char * timestrCHE = getTimeN(call_matrix[j][5]); + char * datestrCHE = getDateN(call_matrix[j][5]); - printw ("%s ", dateCHE); - printw ("%s ", timeCHE); + printw ("%s ", datestrCHE); + printw ("%s ", timestrCHE); - free (dateCHE); - free (timeCHE); + if (datestrCHE != NULL) free (datestrCHE); + if (timestrCHE != NULL) free (timestrCHE); printw ("LCN [%2lld] ", call_matrix[j][1]); if (state->ea_mode == 1) @@ -4840,14 +4840,14 @@ 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); - free (datestr); - free (timestrC); - free (datestrH); + + + + //allocated memory pointer needs to be free'd + if (timestr != NULL) free (timestr); + if (datestr != NULL) free (datestr); + if (timestrC != NULL) free (timestrC); + if (datestrH != NULL) free (datestrH); } //end ncursesPrinter diff --git a/src/edacs-fme.c b/src/edacs-fme.c index 2914683..58a5261 100644 --- a/src/edacs-fme.c +++ b/src/edacs-fme.c @@ -2135,8 +2135,8 @@ void edacs(dsd_opts * opts, dsd_state * state) } - free (timestr); //free allocated memory to prevent memory leak - free (datestr); + if (timestr != NULL) free (timestr); + if (datestr != NULL) free (datestr); fprintf (stderr, "\n"); } diff --git a/src/p25p2_frame.c b/src/p25p2_frame.c index cc408ac..fcda2cb 100644 --- a/src/p25p2_frame.c +++ b/src/p25p2_frame.c @@ -874,7 +874,7 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state) fprintf (stderr,"%s ", timestr); fprintf (stderr, " P25p2 "); - free(timestr); + if (timestr != NULL) free (timestr); if (state->currentslot == 0 && duid_decoded != 3 && duid_decoded != 12 && duid_decoded != 13 && duid_decoded != 4) {