Avoid trying to free NULL ptrs. Comment on malloc usages.

-Erik
This commit is contained in:
Eric Andersen 2000-07-19 17:37:57 +00:00
parent a16c66335e
commit 91a4400fd5
2 changed files with 12 additions and 8 deletions

View File

@ -370,6 +370,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
void get_previous_history(struct history **hp, char* command) void get_previous_history(struct history **hp, char* command)
{ {
if ((*hp)->s)
free((*hp)->s); free((*hp)->s);
(*hp)->s = strdup(command); (*hp)->s = strdup(command);
*hp = (*hp)->p; *hp = (*hp)->p;
@ -377,6 +378,7 @@ void get_previous_history(struct history **hp, char* command)
void get_next_history(struct history **hp, char* command) void get_next_history(struct history **hp, char* command)
{ {
if ((*hp)->s)
free((*hp)->s); free((*hp)->s);
(*hp)->s = strdup(command); (*hp)->s = strdup(command);
*hp = (*hp)->n; *hp = (*hp)->n;
@ -654,7 +656,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
struct history *h = his_end; struct history *h = his_end;
if (!h) { if (!h) {
/* No previous history */ /* No previous history -- this memory is never freed */
h = his_front = malloc(sizeof(struct history)); h = his_front = malloc(sizeof(struct history));
h->n = malloc(sizeof(struct history)); h->n = malloc(sizeof(struct history));
@ -666,7 +668,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
his_end = h->n; his_end = h->n;
history_counter++; history_counter++;
} else { } else {
/* Add a new history command */ /* Add a new history command -- this memory is never freed */
h->n = malloc(sizeof(struct history)); h->n = malloc(sizeof(struct history));
h->n->p = h; h->n->p = h;

View File

@ -370,6 +370,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
void get_previous_history(struct history **hp, char* command) void get_previous_history(struct history **hp, char* command)
{ {
if ((*hp)->s)
free((*hp)->s); free((*hp)->s);
(*hp)->s = strdup(command); (*hp)->s = strdup(command);
*hp = (*hp)->p; *hp = (*hp)->p;
@ -377,6 +378,7 @@ void get_previous_history(struct history **hp, char* command)
void get_next_history(struct history **hp, char* command) void get_next_history(struct history **hp, char* command)
{ {
if ((*hp)->s)
free((*hp)->s); free((*hp)->s);
(*hp)->s = strdup(command); (*hp)->s = strdup(command);
*hp = (*hp)->n; *hp = (*hp)->n;
@ -654,7 +656,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
struct history *h = his_end; struct history *h = his_end;
if (!h) { if (!h) {
/* No previous history */ /* No previous history -- this memory is never freed */
h = his_front = malloc(sizeof(struct history)); h = his_front = malloc(sizeof(struct history));
h->n = malloc(sizeof(struct history)); h->n = malloc(sizeof(struct history));
@ -666,7 +668,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
his_end = h->n; his_end = h->n;
history_counter++; history_counter++;
} else { } else {
/* Add a new history command */ /* Add a new history command -- this memory is never freed */
h->n = malloc(sizeof(struct history)); h->n = malloc(sizeof(struct history));
h->n->p = h; h->n->p = h;