From ae5f793ec07b1e8be640135d255c70a765d3e3d0 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 12 Apr 2016 18:08:33 +0200 Subject: [PATCH] linenoiseFree() API introduced. --- linenoise.c | 8 ++++++++ linenoise.h | 1 + 2 files changed, 9 insertions(+) diff --git a/linenoise.c b/linenoise.c index 193adff..0c1fee2 100644 --- a/linenoise.c +++ b/linenoise.c @@ -1050,6 +1050,14 @@ char *linenoise(const char *prompt) { } } +/* This is just a wrapper the user may want to call in order to make sure + * the linenoise returned buffer is freed with the same allocator it was + * created with. Useful when the main program is using an alternative + * allocator. */ +void linenoiseFree(void *ptr) { + free(ptr); +} + /* ================================ History ================================= */ /* Free the history, but does not reset it. Only used when we have to diff --git a/linenoise.h b/linenoise.h index b1d0a80..3138c1f 100644 --- a/linenoise.h +++ b/linenoise.h @@ -57,6 +57,7 @@ void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *); void linenoiseAddCompletion(linenoiseCompletions *, const char *); char *linenoise(const char *prompt); +void linenoiseFree(void *ptr); int linenoiseHistoryAdd(const char *line); int linenoiseHistorySetMaxLen(int len); int linenoiseHistorySave(const char *filename);