From 776d24e83f5aa3401fe3f05224ca3da89d591aba Mon Sep 17 00:00:00 2001 From: aditi_lonkar Date: Thu, 2 Dec 2021 12:58:01 +0530 Subject: [PATCH] fatfs: Fix some memory leak issues by coverity static analyzer. --- components/fatfs/src/ff.c | 7 ++++++- components/fatfs/src/vfs_fat.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/fatfs/src/ff.c b/components/fatfs/src/ff.c index 5ebdf49191..b00eebeace 100644 --- a/components/fatfs/src/ff.c +++ b/components/fatfs/src/ff.c @@ -5555,7 +5555,12 @@ FRESULT f_mkfs ( sz_buf = len / ss; /* Size of working buffer (sector) */ szb_buf = sz_buf * ss; /* Size of working buffer (byte) */ } - if (!buf || sz_buf == 0) return FR_NOT_ENOUGH_CORE; + if (!buf || sz_buf == 0) { +#if FF_USE_LFN == 3 + ff_memfree(buf); +#endif + return FR_NOT_ENOUGH_CORE; + } /* Determine where the volume to be located (b_vol, sz_vol) */ if (FF_MULTI_PARTITION && part != 0) { diff --git a/components/fatfs/src/vfs_fat.c b/components/fatfs/src/vfs_fat.c index ea74c82ee6..c6096026c7 100644 --- a/components/fatfs/src/vfs_fat.c +++ b/components/fatfs/src/vfs_fat.c @@ -557,12 +557,12 @@ static int vfs_fat_link(void* ctx, const char* n1, const char* n2) } fail3: f_close(pf2); - free(pf2); fail2: f_close(pf1); - free(pf1); fail1: free(buf); + free(pf2); + free(pf1); if (res != FR_OK) { ESP_LOGD(TAG, "%s: fresult=%d", __func__, res); errno = fresult_to_errno(res);