From ddbbdd7fd3568e6f538ddddd74cd8bc78a7922db Mon Sep 17 00:00:00 2001 From: Gao Feng Date: Thu, 15 Aug 2024 17:12:06 +0800 Subject: [PATCH] xtensa/esp32s3: partition name duplicate and free --- arch/xtensa/src/esp32s3/esp32s3_partition.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/xtensa/src/esp32s3/esp32s3_partition.c b/arch/xtensa/src/esp32s3/esp32s3_partition.c index 857f588021..8579debcbf 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_partition.c +++ b/arch/xtensa/src/esp32s3/esp32s3_partition.c @@ -756,7 +756,14 @@ int esp32s3_partition_init(void) mtd_priv->mtd.ioctl = esp32s3_part_ioctl; mtd_priv->mtd.read = esp32s3_part_read; mtd_priv->mtd.write = esp32s3_part_write; - mtd_priv->mtd.name = label; + mtd_priv->mtd.name = strdup(label); + if (!mtd_priv->mtd.name) + { + ferr("ERROR: Failed to allocate MTD name\n"); + kmm_free(mtd_priv); + ret = -ENOSPC; + goto errout_with_mtd; + } mtd_priv->part_mtd = mtd_partition(&mtd_priv->mtd, info->offset / geo.blocksize, @@ -764,6 +771,7 @@ int esp32s3_partition_init(void) if (!mtd_priv->part_mtd) { ferr("ERROR: Failed to create MTD partition\n"); + lib_free(mtd_priv->mtd.name); kmm_free(mtd_priv); ret = -ENOSPC; goto errout_with_mtd; @@ -773,6 +781,7 @@ int esp32s3_partition_init(void) if (ret < 0) { ferr("ERROR: Failed to register MTD @ %s\n", path); + lib_free(mtd_priv->mtd.name); kmm_free(mtd_priv); goto errout_with_mtd; }