void get_previous_history(struct history **hp, char* command)
{
- free((*hp)->s);
+ if ((*hp)->s)
+ free((*hp)->s);
(*hp)->s = strdup(command);
*hp = (*hp)->p;
}
void get_next_history(struct history **hp, char* command)
{
- free((*hp)->s);
+ if ((*hp)->s)
+ free((*hp)->s);
(*hp)->s = strdup(command);
*hp = (*hp)->n;
}
struct history *h = his_end;
if (!h) {
- /* No previous history */
+ /* No previous history -- this memory is never freed */
h = his_front = malloc(sizeof(struct history));
h->n = malloc(sizeof(struct history));
his_end = h->n;
history_counter++;
} else {
- /* Add a new history command */
+ /* Add a new history command -- this memory is never freed */
h->n = malloc(sizeof(struct history));
h->n->p = h;
void get_previous_history(struct history **hp, char* command)
{
- free((*hp)->s);
+ if ((*hp)->s)
+ free((*hp)->s);
(*hp)->s = strdup(command);
*hp = (*hp)->p;
}
void get_next_history(struct history **hp, char* command)
{
- free((*hp)->s);
+ if ((*hp)->s)
+ free((*hp)->s);
(*hp)->s = strdup(command);
*hp = (*hp)->n;
}
struct history *h = his_end;
if (!h) {
- /* No previous history */
+ /* No previous history -- this memory is never freed */
h = his_front = malloc(sizeof(struct history));
h->n = malloc(sizeof(struct history));
his_end = h->n;
history_counter++;
} else {
- /* Add a new history command */
+ /* Add a new history command -- this memory is never freed */
h->n = malloc(sizeof(struct history));
h->n->p = h;