From 9fdf36c17e11eaa1349f68937a5126151ecd1ece Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Sat, 8 Apr 2023 16:22:26 +0800 Subject: [PATCH] drivers/ramdisk: don't free memory for romdisk Signed-off-by: dongjiuzhu1 --- drivers/misc/ramdisk.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/misc/ramdisk.c b/drivers/misc/ramdisk.c index ab3383e750..a761901a2a 100644 --- a/drivers/misc/ramdisk.c +++ b/drivers/misc/ramdisk.c @@ -51,7 +51,7 @@ #define RDFLAG_USER (RDFLAG_WRENABLED | RDFLAG_FUNLINK) #define RDFLAG_IS_WRENABLED(f) (((f) & RDFLAG_WRENABLED) != 0) -#define RDFLAG_IS_FUNLINK(f) (((f) & RDFLAG_WRENABLED) != 0) +#define RDFLAG_IS_FUNLINK(f) (((f) & RDFLAG_FUNLINK) != 0) /* Flag set when the RAM disk block driver is unlink */ @@ -143,7 +143,10 @@ static void rd_destroy(FAR struct rd_struct_s *dev) { /* Yes.. do it */ - kmm_free(dev->rd_buffer); + if (dev->rd_flags & RDFLAG_USER) + { + kmm_free(dev->rd_buffer); + } } /* And free the block driver itself */