From dd15faaa9797b6da9c53fd2d7238f0cae8176f38 Mon Sep 17 00:00:00 2001 From: chenyingchun0312 Date: Sun, 2 Aug 2020 22:19:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BD=9C=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AD=98=E6=B3=84=E9=9C=B2=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=8F=8Art=5Ffree=E6=97=B6=EF=BC=8C=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/file/listdir.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/file/listdir.c b/examples/file/listdir.c index 98419db873..3300389ab9 100644 --- a/examples/file/listdir.c +++ b/examples/file/listdir.c @@ -13,7 +13,7 @@ void list_dir(const char* path) { - char * fullpath; + char * fullpath = RT_NULL; DIR *dir; dir = opendir(path); @@ -26,6 +26,7 @@ void list_dir(const char* path) if (fullpath == RT_NULL) { rt_kprintf("no memory\n"); + closedir(dir); return; } @@ -55,8 +56,13 @@ void list_dir(const char* path) { rt_kprintf("open %s directory failed\n", path); } - - rt_free(fullpath); + + if (RT_NULL != fullpath) + { + rt_free(fullpath); + fullpath = RT_NULL; + } + } #ifdef RT_USING_FINSH -- Gitee