From b4c2ea2cece1adeaa915f6c12f310f2268a58751 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 10 Jul 2009 21:32:44 +0000 Subject: 27125: handle nested use of colour code buffer allocation --- Src/prompt.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Src') diff --git a/Src/prompt.c b/Src/prompt.c index e56b70d0b..afb9777a0 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -1764,13 +1764,18 @@ struct colour_sequences { struct colour_sequences fg_bg_sequences[2]; /* - * We need a buffer for colour sequence compostion. It may + * We need a buffer for colour sequence composition. It may * vary depending on the sequences set. However, it's inefficient * allocating it separately every time we send a colour sequence, * so do it once per refresh. */ static char *colseq_buf; +/* + * Count how often this has been allocated, for recursive usage. + */ +static int colseq_buf_allocs; + /**/ void set_default_colour_sequences(void) @@ -1801,9 +1806,13 @@ set_colour_code(char *str, char **var) mod_export void allocate_colour_buffer(void) { - char **atrs = getaparam("zle_highlight"); + char **atrs; int lenfg, lenbg, len; + if (colseq_buf_allocs++) + return; + + atrs = getaparam("zle_highlight"); if (atrs) { for (; *atrs; atrs++) { if (strpfx("fg_start_code:", *atrs)) { @@ -1846,6 +1855,9 @@ allocate_colour_buffer(void) mod_export void free_colour_buffer(void) { + if (--colseq_buf_allocs) + return; + DPUTS(!colseq_buf, "Freeing colour sequence buffer without alloc"); /* Free buffer for colour code composition */ free(colseq_buf); -- cgit 1.4.1