aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-12-09 21:29:00 +0300
committerJoursoir <chat@joursoir.net>2021-12-09 21:29:00 +0300
commit235d3f2db54d1f745dca618ed2ca236cf6e84245 (patch)
treeb8a2eda518bfbfbc8cac051a8cfb23d64ac8868f
parent1205492d1c6bf7d8e938b47a76f7d0e4a8a8844f (diff)
downloadufm-235d3f2db54d1f745dca618ed2ca236cf6e84245.tar.gz
ufm-235d3f2db54d1f745dca618ed2ca236cf6e84245.tar.bz2
ufm-235d3f2db54d1f745dca618ed2ca236cf6e84245.zip
panel: fix frees memory during change cwd
-rw-r--r--Library/UefiShellUfmCommandLib/panel.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/Library/UefiShellUfmCommandLib/panel.c b/Library/UefiShellUfmCommandLib/panel.c
index 986f1fb..328a7ef 100644
--- a/Library/UefiShellUfmCommandLib/panel.c
+++ b/Library/UefiShellUfmCommandLib/panel.c
@@ -301,28 +301,36 @@ BOOLEAN panel_move_cursor(struct panel_ctx *p, UINTN line)
BOOLEAN panel_cd_to(struct panel_ctx *p, CONST CHAR16 *path)
{
- struct fs_array *fsa = NULL;
- struct dir_list *dirs = NULL;
+ CHAR16 *own_path = NULL;
ASSERT(p != NULL);
+ // We make a copy of the path string because the next step is to
+ // free the struct dir_list
if(path) {
- dirs = scandir(path, L"*", 0);
- if(!dirs)
- return FALSE;
- }
- else {
- fsa = scanfs();
- if(!fsa)
+ own_path = AllocateCopyPool(StrSize(path) + 1, path);
+ if(!own_path)
return FALSE;
}
- set_cwd(p, path);
- if(p->dirs)
+ if(p->dirs) {
dirl_release(p->dirs);
- if(p->fsa)
+ p->dirs = NULL;
+ }
+ if(p->fsa) {
fsa_release(p->fsa);
- p->dirs = dirs;
- p->fsa = fsa;
+ p->fsa = NULL;
+ }
+
+ if(own_path) {
+ p->dirs = scandir(own_path, L"*", 0);
+ ASSERT(p->dirs != NULL);
+ }
+ else {
+ p->fsa = scanfs();
+ ASSERT(p->fsa != NULL);
+ }
+
+ set_cwd(p, own_path);
p->marked = 0;
p->start_entry = 0;