From 9d02ffaea407763f51d1a4313ca7bd964fc6c4db Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Fri, 26 Mar 2021 17:50:06 +0100 Subject: [PATCH] Fix for #20, caused by a memory leak when clearing information about GPS satellites in state data structure --- openrtx/src/gps.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/openrtx/src/gps.c b/openrtx/src/gps.c index 20a0dfc3..a53c7e99 100644 --- a/openrtx/src/gps.c +++ b/openrtx/src/gps.c @@ -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;