rl_unintialize(): New function, free all memory after use

Free all allocated internal memory and reset variables so
rl_initialize() or readline() may be called again later.

Signed-off-by: Claus Fischer <claus.fischer@clausfischer.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Claus Fischer 2017-11-29 14:42:39 +01:00 committed by Joachim Nilsson
parent ed87f37409
commit 317b43e488
2 changed files with 25 additions and 0 deletions

View File

@ -82,6 +82,7 @@ extern int el_hist_size; /* size of history scrollback buffer, default:
extern void rl_initialize(void); extern void rl_initialize(void);
extern void rl_reset_terminal(const char *terminal_name); extern void rl_reset_terminal(const char *terminal_name);
extern void rl_uninitialize(void);
void rl_save_prompt(void); void rl_save_prompt(void);
void rl_restore_prompt(void); void rl_restore_prompt(void);

View File

@ -1145,6 +1145,30 @@ void rl_initialize(void)
if (el_outfd < 0) el_outfd = EL_STDOUT; if (el_outfd < 0) el_outfd = EL_STDOUT;
} }
void rl_uninitialize(void)
{
int i;
/* Uninitialize the history */
if (H.Lines) {
for (i = 0; i < el_hist_size; i++) {
if (H.Lines[i])
free(H.Lines[i]);
H.Lines[i] = 0;
}
free(H.Lines);
H.Lines = 0;
}
H.Size = 0;
H.Pos = 0;
/* Uninitialize the line buffer */
if (rl_line_buffer)
free(rl_line_buffer);
rl_line_buffer = NULL;
Length = 0;
}
static const char *rl_saved_prompt = NULL; static const char *rl_saved_prompt = NULL;
void rl_save_prompt(void) void rl_save_prompt(void)
{ {