diff options
| author | Meco Man <[email protected]> | 2021-06-12 16:08:22 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2021-06-12 16:11:57 +0800 |
| commit | a3b1caf952717fc79a589a870a0caf50538bc76d (patch) | |
| tree | ed177574bed4c07d73488aa40bed097353e1c201 /examples | |
| parent | 5c8625c8ef6deff6979d990f1638200029978dd2 (diff) | |
[example] 解决潜在内存泄漏问题
重新解决冲突,源自:https://gitee.com/rtthread/rt-thread/pulls/48/files
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/file/listdir.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/examples/file/listdir.c b/examples/file/listdir.c index 98fbc5ea2c..06c746a642 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); @@ -57,7 +57,10 @@ void list_dir(const char* path) rt_kprintf("open %s directory failed\n", path); } - rt_free(fullpath); + if (RT_NULL != fullpath) + { + rt_free(fullpath); + } } #ifdef RT_USING_FINSH @@ -80,6 +83,6 @@ static void cmd_list_dir(int argc, char *argv[]) } list_dir(filename); } -FINSH_FUNCTION_EXPORT_ALIAS(cmd_list_dir, __cmd_list_dir, list directory); +MSH_CMD_EXPORT_ALIAS(cmd_list_dir, list_dir, list directory); #endif /* FINSH_USING_MSH */ #endif /* RT_USING_FINSH */ |
