From 67686c231a0e84180e80bfa8e1a7ee1696d77c8f Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 9 Nov 2022 18:21:07 +0800 Subject: [PATCH] Call nxmutex_destroy and nxsem_destroy in error patch to avoid the leak Signed-off-by: Xiang Xiao --- arch/arm/src/cxd56xx/cxd56_geofence.c | 1 + arch/arm/src/cxd56xx/cxd56_gnss.c | 3 +++ arch/arm/src/lc823450/lc823450_adc.c | 9 ++++++--- arch/arm/src/rp2040/rp2040_i2s.c | 1 + arch/arm/src/sama5/sam_ssc.c | 1 + arch/arm/src/samv7/sam_ssc.c | 1 + arch/arm/src/stm32/stm32_i2s.c | 1 + boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c | 1 + boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c | 1 + 9 files changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/arm/src/cxd56xx/cxd56_geofence.c b/arch/arm/src/cxd56xx/cxd56_geofence.c index 00c83f8a9e..f5b5bb7592 100644 --- a/arch/arm/src/cxd56xx/cxd56_geofence.c +++ b/arch/arm/src/cxd56xx/cxd56_geofence.c @@ -673,6 +673,7 @@ err1: unregister_driver(devpath); err0: + nxmutex_destroy(&priv->devlock); kmm_free(priv); return ret; } diff --git a/arch/arm/src/cxd56xx/cxd56_gnss.c b/arch/arm/src/cxd56xx/cxd56_gnss.c index 84082d4821..3b11035613 100644 --- a/arch/arm/src/cxd56xx/cxd56_gnss.c +++ b/arch/arm/src/cxd56xx/cxd56_gnss.c @@ -3175,6 +3175,9 @@ err1: unregister_driver(devpath); err0: + nxmutex_destroy(&priv->ioctllock); + nxsem_destroy(&priv->apiwait); + nxmutex_destroy(&priv->devlock); kmm_free(priv); return ret; } diff --git a/arch/arm/src/lc823450/lc823450_adc.c b/arch/arm/src/lc823450/lc823450_adc.c index 4751aa8cb8..76d82333ce 100644 --- a/arch/arm/src/lc823450/lc823450_adc.c +++ b/arch/arm/src/lc823450/lc823450_adc.c @@ -514,7 +514,9 @@ struct adc_dev_s *lc823450_adcinitialize(void) if (ret < 0) { aerr("adc_register failed: %d\n", ret); - kmm_free(g_inst); + nxmutex_destroy(&inst->lock); + nxsem_destroy(&inst->sem_isr); + kmm_free(inst); return NULL; } @@ -541,12 +543,13 @@ struct adc_dev_s *lc823450_adcinitialize(void) /* Register the ADC driver at "/dev/adc0" */ ret = adc_register("/dev/adc0", &inst->dev); - if (ret < 0) { aerr("adc_register failed: %d\n", ret); nxmutex_unlock(&inst->lock); - kmm_free(g_inst); + nxmutex_destroy(&inst->lock); + nxsem_destroy(&inst->sem_isr); + kmm_free(inst); return NULL; } diff --git a/arch/arm/src/rp2040/rp2040_i2s.c b/arch/arm/src/rp2040/rp2040_i2s.c index b92b199202..e88097e9f9 100644 --- a/arch/arm/src/rp2040/rp2040_i2s.c +++ b/arch/arm/src/rp2040/rp2040_i2s.c @@ -1333,6 +1333,7 @@ struct i2s_dev_s *rp2040_i2sbus_initialize(int port) errout_with_alloc: nxmutex_destroy(&priv->lock); + nxsem_destroy(&priv->bufsem); kmm_free(priv); return NULL; } diff --git a/arch/arm/src/sama5/sam_ssc.c b/arch/arm/src/sama5/sam_ssc.c index 67729c568c..5277a11619 100644 --- a/arch/arm/src/sama5/sam_ssc.c +++ b/arch/arm/src/sama5/sam_ssc.c @@ -3422,6 +3422,7 @@ errout_with_clocking: errout_with_alloc: nxmutex_destroy(&priv->lock); + nxsem_destroy(&priv->bufsem); kmm_free(priv); return NULL; } diff --git a/arch/arm/src/samv7/sam_ssc.c b/arch/arm/src/samv7/sam_ssc.c index 43e6ced60c..071be7bc33 100644 --- a/arch/arm/src/samv7/sam_ssc.c +++ b/arch/arm/src/samv7/sam_ssc.c @@ -3404,6 +3404,7 @@ errout_with_clocking: errout_with_alloc: nxmutex_destroy(&priv->lock); + nxsem_destroy(&priv->bufsem); kmm_free(priv); return NULL; } diff --git a/arch/arm/src/stm32/stm32_i2s.c b/arch/arm/src/stm32/stm32_i2s.c index d078669741..c9dadf6bc2 100644 --- a/arch/arm/src/stm32/stm32_i2s.c +++ b/arch/arm/src/stm32/stm32_i2s.c @@ -2600,6 +2600,7 @@ struct i2s_dev_s *stm32_i2sbus_initialize(int port) errout_with_alloc: leave_critical_section(flags); nxmutex_destroy(&priv->lock); + nxsem_destroy(&priv->bufsem); kmm_free(priv); return NULL; } diff --git a/boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c b/boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c index 25f90b6bbb..5e3725e7ed 100644 --- a/boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c +++ b/boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c @@ -1539,6 +1539,7 @@ int stm32_tsc_setup(int minor) errout_with_priv: nxmutex_destroy(&priv->devlock); + nxsem_destroy(&priv->waitsem); #ifdef CONFIG_TOUCHSCREEN_MULTIPLE kmm_free(priv); #endif diff --git a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c b/boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c index 8f1ab3f7f7..7684c58e57 100644 --- a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c +++ b/boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c @@ -1399,6 +1399,7 @@ int pic32mx_tsc_setup(int minor) errout_with_priv: nxmutex_destroy(&priv->devlock); + nxsem_destroy(&priv->waitsem); #ifdef CONFIG_TOUCHSCREEN_MULTIPLE kmm_free(priv); #endif