gpt: free gpt_pte memory before we get a new one

The memory leak will happen if there is a dev access switch, fix it
by free the memory before we get a new one.

Change-Id: I5d11609ab5b6cc37f2812d901f2427a1c83fd3a4
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
This commit is contained in:
Kever Yang 2018-09-05 11:27:48 +08:00 committed by Jianhong Chen
parent e2bd44da4a
commit 1b4602e039
1 changed files with 8 additions and 2 deletions

View File

@ -275,9 +275,15 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,
if (!gpt_head)
gpt_head = memalign(ARCH_DMA_MINALIGN, dev_desc->blksz);
/* We suppose different dev have different size, eg. emmc vs sd */
if (gpt_head && (gpt_head->last_usable_lba + 0x22) != dev_desc->lba)
/*
* We suppose different dev have different size, eg. emmc vs sd
* free the pte first if exist and then will malloc and init a new one.
*/
if (gpt_head && (gpt_head->last_usable_lba + 0x22) != dev_desc->lba) {
if (gpt_pte)
free(gpt_pte);
gpt_pte = NULL;
}
/* "part" argument must be at least 1 */
if (part < 1) {