diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-07-19 17:37:57 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-07-19 17:37:57 +0000 |
commit | 91a4400fd5a74c6e954b22b276dd38c7ffaeae33 (patch) | |
tree | 33cf648853df478b733452c48f665e35ad65dc1f | |
parent | a16c66335e24009c4cbcd57ce8205b4dfc7b099c (diff) | |
download | busybox-w32-91a4400fd5a74c6e954b22b276dd38c7ffaeae33.tar.gz busybox-w32-91a4400fd5a74c6e954b22b276dd38c7ffaeae33.tar.bz2 busybox-w32-91a4400fd5a74c6e954b22b276dd38c7ffaeae33.zip |
Avoid trying to free NULL ptrs. Comment on malloc usages.
-Erik
-rw-r--r-- | cmdedit.c | 10 | ||||
-rw-r--r-- | shell/cmdedit.c | 10 |
2 files changed, 12 insertions, 8 deletions
@@ -370,14 +370,16 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len) | |||
370 | 370 | ||
371 | void get_previous_history(struct history **hp, char* command) | 371 | void get_previous_history(struct history **hp, char* command) |
372 | { | 372 | { |
373 | free((*hp)->s); | 373 | if ((*hp)->s) |
374 | free((*hp)->s); | ||
374 | (*hp)->s = strdup(command); | 375 | (*hp)->s = strdup(command); |
375 | *hp = (*hp)->p; | 376 | *hp = (*hp)->p; |
376 | } | 377 | } |
377 | 378 | ||
378 | void get_next_history(struct history **hp, char* command) | 379 | void get_next_history(struct history **hp, char* command) |
379 | { | 380 | { |
380 | free((*hp)->s); | 381 | if ((*hp)->s) |
382 | free((*hp)->s); | ||
381 | (*hp)->s = strdup(command); | 383 | (*hp)->s = strdup(command); |
382 | *hp = (*hp)->n; | 384 | *hp = (*hp)->n; |
383 | } | 385 | } |
@@ -654,7 +656,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
654 | struct history *h = his_end; | 656 | struct history *h = his_end; |
655 | 657 | ||
656 | if (!h) { | 658 | if (!h) { |
657 | /* No previous history */ | 659 | /* No previous history -- this memory is never freed */ |
658 | h = his_front = malloc(sizeof(struct history)); | 660 | h = his_front = malloc(sizeof(struct history)); |
659 | h->n = malloc(sizeof(struct history)); | 661 | h->n = malloc(sizeof(struct history)); |
660 | 662 | ||
@@ -666,7 +668,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
666 | his_end = h->n; | 668 | his_end = h->n; |
667 | history_counter++; | 669 | history_counter++; |
668 | } else { | 670 | } else { |
669 | /* Add a new history command */ | 671 | /* Add a new history command -- this memory is never freed */ |
670 | h->n = malloc(sizeof(struct history)); | 672 | h->n = malloc(sizeof(struct history)); |
671 | 673 | ||
672 | h->n->p = h; | 674 | h->n->p = h; |
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index 0f064b414..0de18e81f 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
@@ -370,14 +370,16 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len) | |||
370 | 370 | ||
371 | void get_previous_history(struct history **hp, char* command) | 371 | void get_previous_history(struct history **hp, char* command) |
372 | { | 372 | { |
373 | free((*hp)->s); | 373 | if ((*hp)->s) |
374 | free((*hp)->s); | ||
374 | (*hp)->s = strdup(command); | 375 | (*hp)->s = strdup(command); |
375 | *hp = (*hp)->p; | 376 | *hp = (*hp)->p; |
376 | } | 377 | } |
377 | 378 | ||
378 | void get_next_history(struct history **hp, char* command) | 379 | void get_next_history(struct history **hp, char* command) |
379 | { | 380 | { |
380 | free((*hp)->s); | 381 | if ((*hp)->s) |
382 | free((*hp)->s); | ||
381 | (*hp)->s = strdup(command); | 383 | (*hp)->s = strdup(command); |
382 | *hp = (*hp)->n; | 384 | *hp = (*hp)->n; |
383 | } | 385 | } |
@@ -654,7 +656,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
654 | struct history *h = his_end; | 656 | struct history *h = his_end; |
655 | 657 | ||
656 | if (!h) { | 658 | if (!h) { |
657 | /* No previous history */ | 659 | /* No previous history -- this memory is never freed */ |
658 | h = his_front = malloc(sizeof(struct history)); | 660 | h = his_front = malloc(sizeof(struct history)); |
659 | h->n = malloc(sizeof(struct history)); | 661 | h->n = malloc(sizeof(struct history)); |
660 | 662 | ||
@@ -666,7 +668,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
666 | his_end = h->n; | 668 | his_end = h->n; |
667 | history_counter++; | 669 | history_counter++; |
668 | } else { | 670 | } else { |
669 | /* Add a new history command */ | 671 | /* Add a new history command -- this memory is never freed */ |
670 | h->n = malloc(sizeof(struct history)); | 672 | h->n = malloc(sizeof(struct history)); |
671 | 673 | ||
672 | h->n->p = h; | 674 | h->n->p = h; |