Fix for #20, caused by a memory leak when clearing information about GPS satellites in state data structure

replace/5219c00331556ab6898d303882d74f39d9584a28
Silvano Seva 2021-03-26 17:50:06 +01:00
rodzic 7f9600cdb7
commit 9d02ffaea4
1 zmienionych plików z 8 dodań i 7 usunięć

Wyświetl plik

@ -108,9 +108,16 @@ void gps_taskFunc(char *line, __attribute__((unused)) int len, state_t *state)
case MINMEA_SENTENCE_GSV:
{
// Parse only sentences 1 - 3, maximum 12 satellites
struct minmea_sentence_gsv frame;
if (minmea_parse_gsv(&frame, line))
if (minmea_parse_gsv(&frame, line) && (frame.msg_nr < 3))
{
// When the first sentence arrives, clear all the old data
if (frame.msg_nr == 1)
{
bzero(&state->gps_data.satellites[0], 12 * sizeof(sat_t));
}
state->gps_data.satellites_in_view = frame.total_sats;
for (int i = 0; i < 4; i++)
{
@ -120,12 +127,6 @@ void gps_taskFunc(char *line, __attribute__((unused)) int len, state_t *state)
state->gps_data.satellites[index].azimuth = frame.sats[i].azimuth;
state->gps_data.satellites[index].snr = frame.sats[i].snr;
}
// Zero out unused satellite slots
if (frame.msg_nr == frame.total_msgs && frame.total_msgs < 3)
{
bzero(&state->gps_data.satellites[4 * frame.msg_nr],
sizeof(sat_t) * 12 - frame.total_msgs * 4);
}
}
} break;