From: Spencer Oliver Date: Sat, 29 May 2010 14:43:42 +0000 (+0100) Subject: nor: fix memory leaks during probe X-Git-Tag: v0.5.0-rc1~660 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=86e851e1e263c79f19eb9db52553de99f19b8bb9;p=openocd nor: fix memory leaks during probe Fix similar memory leaks as per commit: ef72484b785ec7462a0415afea679d08b864c7fb Signed-off-by: Spencer Oliver --- diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c index 7cdab519..8472d836 100644 --- a/src/flash/nor/avrf.c +++ b/src/flash/nor/avrf.c @@ -324,6 +324,12 @@ static int avrf_probe(struct flash_bank *bank) if (avr_info != NULL) { + if (bank->sectors) + { + free(bank->sectors); + bank->sectors = NULL; + } + // chip found bank->base = 0x00000000; bank->size = (avr_info->flash_page_size * avr_info->flash_page_num); diff --git a/src/flash/nor/pic32mx.c b/src/flash/nor/pic32mx.c index 58009ae5..2fe864d4 100644 --- a/src/flash/nor/pic32mx.c +++ b/src/flash/nor/pic32mx.c @@ -560,6 +560,12 @@ static int pic32mx_probe(struct flash_bank *bank) LOG_INFO("flash size = %" PRId32 "kbytes", num_pages / 1024); + if (bank->sectors) + { + free(bank->sectors); + bank->sectors = NULL; + } + /* calculate numbers of pages */ num_pages /= page_size; bank->size = (num_pages * page_size); diff --git a/src/flash/nor/stellaris.c b/src/flash/nor/stellaris.c index 38374ffe..f7e2e8d9 100644 --- a/src/flash/nor/stellaris.c +++ b/src/flash/nor/stellaris.c @@ -1065,6 +1065,12 @@ static int stellaris_probe(struct flash_bank *bank) if (retval != ERROR_OK) return retval; + if (bank->sectors) + { + free(bank->sectors); + bank->sectors = NULL; + } + /* provide this for the benefit of the NOR flash framework */ bank->size = 1024 * stellaris_info->num_pages; bank->num_sectors = stellaris_info->num_pages; diff --git a/src/flash/nor/stm32x.c b/src/flash/nor/stm32x.c index d11a8edc..8a3b8323 100644 --- a/src/flash/nor/stm32x.c +++ b/src/flash/nor/stm32x.c @@ -775,6 +775,12 @@ static int stm32x_probe(struct flash_bank *bank) /* calculate numbers of pages */ num_pages /= (page_size / 1024); + if (bank->sectors) + { + free(bank->sectors); + bank->sectors = NULL; + } + bank->base = 0x08000000; bank->size = (num_pages * page_size); bank->num_sectors = num_pages; diff --git a/src/flash/nor/tms470.c b/src/flash/nor/tms470.c index c1681f19..343c43ed 100644 --- a/src/flash/nor/tms470.c +++ b/src/flash/nor/tms470.c @@ -139,6 +139,12 @@ static int tms470_read_part_info(struct flash_bank *bank) rom_flash = (device_ident_reg >> 10) & 1; part_number = (device_ident_reg >> 3) & 0x7f; + if (bank->sectors) + { + free(bank->sectors); + bank->sectors = NULL; + } + /* * If the part number is known, determine if the flash bank is valid * based on the base address being within the known flash bank