diff options
-rw-r--r-- | shell/hush.c | 2 | ||||
-rw-r--r-- | shell/lash.c | 28 |
2 files changed, 15 insertions, 15 deletions
diff --git a/shell/hush.c b/shell/hush.c index 9af7f5105..eae0e10f5 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -423,7 +423,7 @@ static const struct built_in_command bltins[] = { | |||
423 | static const char *set_cwd(void) | 423 | static const char *set_cwd(void) |
424 | { | 424 | { |
425 | if (cwd == bb_msg_unknown) | 425 | if (cwd == bb_msg_unknown) |
426 | cwd = NULL; /* xrealloc_getcwd_or_warn(arg) called free(arg) */ | 426 | cwd = NULL; /* xrealloc_getcwd_or_warn(arg) calls free(arg)! */ |
427 | cwd = xrealloc_getcwd_or_warn((char *)cwd); | 427 | cwd = xrealloc_getcwd_or_warn((char *)cwd); |
428 | if (!cwd) | 428 | if (!cwd) |
429 | cwd = bb_msg_unknown; | 429 | cwd = bb_msg_unknown; |
diff --git a/shell/lash.c b/shell/lash.c index 5f2dacd18..729d102c6 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -153,7 +153,7 @@ static int shell_context; /* Type prompt trigger (PS1 or PS2) */ | |||
153 | 153 | ||
154 | 154 | ||
155 | /* Globals that are static to this file */ | 155 | /* Globals that are static to this file */ |
156 | static const char *cwd; | 156 | static char *cwd; |
157 | static char *local_pending_command; | 157 | static char *local_pending_command; |
158 | static struct jobset job_list = { NULL, NULL }; | 158 | static struct jobset job_list = { NULL, NULL }; |
159 | static int argc; | 159 | static int argc; |
@@ -207,6 +207,14 @@ So cmd->text becomes child->family->text | |||
207 | job_list becomes child->family->job_list | 207 | job_list becomes child->family->job_list |
208 | */ | 208 | */ |
209 | 209 | ||
210 | |||
211 | static void update_cwd(void) | ||
212 | { | ||
213 | cwd = xrealloc_getcwd_or_warn(cwd); | ||
214 | if (!cwd) | ||
215 | cwd = xstrdup(bb_msg_unknown); | ||
216 | } | ||
217 | |||
210 | /* built-in 'cd <path>' handler */ | 218 | /* built-in 'cd <path>' handler */ |
211 | static int builtin_cd(struct child_prog *child) | 219 | static int builtin_cd(struct child_prog *child) |
212 | { | 220 | { |
@@ -220,9 +228,7 @@ static int builtin_cd(struct child_prog *child) | |||
220 | bb_perror_msg("cd: %s", newdir); | 228 | bb_perror_msg("cd: %s", newdir); |
221 | return EXIT_FAILURE; | 229 | return EXIT_FAILURE; |
222 | } | 230 | } |
223 | cwd = xrealloc_getcwd_or_warn((char *)cwd); | 231 | update_cwd(); |
224 | if (!cwd) | ||
225 | cwd = bb_msg_unknown; | ||
226 | return EXIT_SUCCESS; | 232 | return EXIT_SUCCESS; |
227 | } | 233 | } |
228 | 234 | ||
@@ -347,9 +353,7 @@ static int builtin_jobs(struct child_prog *child) | |||
347 | /* built-in 'pwd' handler */ | 353 | /* built-in 'pwd' handler */ |
348 | static int builtin_pwd(struct child_prog ATTRIBUTE_UNUSED *dummy) | 354 | static int builtin_pwd(struct child_prog ATTRIBUTE_UNUSED *dummy) |
349 | { | 355 | { |
350 | cwd = xrealloc_getcwd_or_warn((char *)cwd); | 356 | update_cwd(); |
351 | if (!cwd) | ||
352 | cwd = bb_msg_unknown; | ||
353 | puts(cwd); | 357 | puts(cwd); |
354 | return EXIT_SUCCESS; | 358 | return EXIT_SUCCESS; |
355 | } | 359 | } |
@@ -1452,9 +1456,7 @@ static int busy_loop(FILE * input) | |||
1452 | #if ENABLE_FEATURE_CLEAN_UP | 1456 | #if ENABLE_FEATURE_CLEAN_UP |
1453 | static void free_memory(void) | 1457 | static void free_memory(void) |
1454 | { | 1458 | { |
1455 | if (cwd && cwd != bb_msg_unknown) { | 1459 | free(cwd); |
1456 | free((char*)cwd); | ||
1457 | } | ||
1458 | 1460 | ||
1459 | if (job_list.fg && !job_list.fg->running_progs) { | 1461 | if (job_list.fg && !job_list.fg->running_progs) { |
1460 | remove_job(&job_list, job_list.fg); | 1462 | remove_job(&job_list, job_list.fg); |
@@ -1571,14 +1573,12 @@ int lash_main(int argc_l, char **argv_l) | |||
1571 | } | 1573 | } |
1572 | 1574 | ||
1573 | /* initialize the cwd -- this is never freed...*/ | 1575 | /* initialize the cwd -- this is never freed...*/ |
1574 | cwd = xrealloc_getcwd_or_warn(NULL); | 1576 | update_cwd(); |
1575 | if (!cwd) | ||
1576 | cwd = bb_msg_unknown; | ||
1577 | 1577 | ||
1578 | if (ENABLE_FEATURE_CLEAN_UP) atexit(free_memory); | 1578 | if (ENABLE_FEATURE_CLEAN_UP) atexit(free_memory); |
1579 | 1579 | ||
1580 | if (ENABLE_FEATURE_EDITING) cmdedit_set_initial_prompt(); | 1580 | if (ENABLE_FEATURE_EDITING) cmdedit_set_initial_prompt(); |
1581 | else PS1 = NULL; | 1581 | else PS1 = NULL; |
1582 | 1582 | ||
1583 | return (busy_loop(input)); | 1583 | return busy_loop(input); |
1584 | } | 1584 | } |