From 75b87a85dd419ca0af7351584466fb6f2aec9a8f Mon Sep 17 00:00:00 2001 From: xuxingliang Date: Fri, 23 Aug 2024 19:44:11 +0800 Subject: [PATCH] rptun: fix memleak on failure Leak backtrace: 1 14 2096 9886 0x4318d768 [0x040320744] romfs/fs_romfsutil.c:1039 [0x04031fd3e] romfs/fs_romfs.c:281 [0x04027fa9e] vfs/fs_open.c:244 [0x0402ab986] rptun/rptun.c:955 [0x04034cc88] open-amp/lib/remoteproc/remoteproc.c:452 [0x0402ac8ac] rptun/rptun.c:748 [0x0402ad038] rptun/rptun.c:618 Signed-off-by: xuxingliang --- drivers/rptun/rptun.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index 0a026998388..144bae67a4f 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -1022,7 +1022,13 @@ static int rptun_store_open(FAR void *store_, *img_data = store->buf; - return file_read(&store->file, store->buf, len); + ret = file_read(&store->file, store->buf, len); + if (ret < 0) + { + file_close(&store->file); + } + + return ret; } static void rptun_store_close(FAR void *store_)