From 6e4f134238c85b26674213c333b63cc8b605095b Mon Sep 17 00:00:00 2001 From: M Mithilesh Date: Tue, 13 Jan 2026 23:01:31 +0530 Subject: [PATCH] bsps/flash: Fix resource leak in flash_sim_flashdev_init (CID 1679602) The allocation of ftable was not freed in error handling paths. This patch ensures ftable is freed if subsequent allocations fail. CID 1679602 --- bsps/shared/dev/flash/flash_sim_flashdev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bsps/shared/dev/flash/flash_sim_flashdev.c b/bsps/shared/dev/flash/flash_sim_flashdev.c index ca4086cc93..edcdf407bc 100644 --- a/bsps/shared/dev/flash/flash_sim_flashdev.c +++ b/bsps/shared/dev/flash/flash_sim_flashdev.c @@ -414,6 +414,7 @@ rtems_flashdev *flash_sim_flashdev_init( ntable->area = flashdev_malloc( &ntable->attr, total_pages * ntable->attr.page_size_bytes ); if ( ntable->area == NULL ) { + free( ftable ); free_nand_priv( ntable ); return NULL; } @@ -422,6 +423,7 @@ rtems_flashdev *flash_sim_flashdev_init( if ( ntable->attr.type == RTEMS_FLASHDEV_NAND ) { ntable->oob = flashdev_malloc( &ntable->attr, total_pages * ntable->attr.page_oob_bytes ); if ( ntable->oob == NULL ) { + free( ftable ); free_nand_priv( ntable ); return NULL; }