From f72fc3dbee0d2306551c0705d87e832a28aac934 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Mon, 12 Jan 2015 00:22:54 +0000 Subject: [PATCH] Fix a couple of problems found by valgrind. --- dump1090.c | 5 ++--- dump1090.h | 2 +- mode_s.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dump1090.c b/dump1090.c index ec81c9f..5fc6db9 100644 --- a/dump1090.c +++ b/dump1090.c @@ -98,10 +98,10 @@ void modesInit(void) { pthread_cond_init(&Modes.data_cond,NULL); // Allocate the various buffers used by Modes - Modes.trailing_space = Modes.oversample ? (MODES_OS_PREAMBLE_SIZE + MODES_OS_LONG_MSG_SIZE) : (MODES_PREAMBLE_SIZE + MODES_LONG_MSG_SIZE) + 1; + Modes.trailing_samples = (Modes.oversample ? (MODES_OS_PREAMBLE_SAMPLES + MODES_OS_LONG_MSG_SAMPLES) : (MODES_PREAMBLE_SAMPLES + MODES_LONG_MSG_SAMPLES)) + 16; if ( ((Modes.icao_cache = (uint32_t *) malloc(sizeof(uint32_t) * MODES_ICAO_CACHE_LEN * 2) ) == NULL) || ((Modes.pFileData = (uint16_t *) malloc(MODES_ASYNC_BUF_SIZE) ) == NULL) || - ((Modes.magnitude = (uint16_t *) malloc(MODES_ASYNC_BUF_SIZE+Modes.trailing_space) ) == NULL) || + ((Modes.magnitude = (uint16_t *) calloc(MODES_ASYNC_BUF_SAMPLES+Modes.trailing_samples, 2) ) == NULL) || ((Modes.maglut = (uint16_t *) malloc(sizeof(uint16_t) * 256 * 256) ) == NULL) || ((Modes.log10lut = (uint16_t *) malloc(sizeof(uint16_t) * 256 * 256) ) == NULL) ) { @@ -112,7 +112,6 @@ void modesInit(void) { // Clear the buffers that have just been allocated, just in-case memset(Modes.icao_cache, 0, sizeof(uint32_t) * MODES_ICAO_CACHE_LEN * 2); memset(Modes.pFileData,127, MODES_ASYNC_BUF_SIZE); - memset(Modes.magnitude, 0, MODES_ASYNC_BUF_SIZE+Modes.trailing_space); // Validate the users Lat/Lon home location inputs if ( (Modes.fUserLat > 90.0) // Latitude must be -90 to +90 diff --git a/dump1090.h b/dump1090.h index b9ebcb7..a12f46a 100644 --- a/dump1090.h +++ b/dump1090.h @@ -288,7 +288,7 @@ struct { // Internal state int iDataReady; // Fifo content count int iDataLost; // Count of missed buffers - int trailing_space; // extra trailing space needed by magnitude buffer + int trailing_samples;// extra trailing samples in magnitude buffer uint16_t *pFileData; // Raw IQ samples buffer (from a File) uint16_t *magnitude; // Magnitude vector diff --git a/mode_s.c b/mode_s.c index 088da82..9aae7fc 100644 --- a/mode_s.c +++ b/mode_s.c @@ -1433,10 +1433,10 @@ void displayModesMessage(struct modesMessage *mm) { // pointed by Modes.magnitude. // void computeMagnitudeVector(uint16_t *p) { - uint16_t *m = &Modes.magnitude[Modes.trailing_space]; + uint16_t *m = &Modes.magnitude[Modes.trailing_samples]; uint32_t j; - memcpy(Modes.magnitude,&Modes.magnitude[MODES_ASYNC_BUF_SAMPLES], Modes.trailing_space); + memcpy(Modes.magnitude,&Modes.magnitude[MODES_ASYNC_BUF_SAMPLES], Modes.trailing_samples * 2); // Compute the magnitudo vector. It's just SQRT(I^2 + Q^2), but // we rescale to the 0-255 range to exploit the full resolution.