degesch: set a limit on backlog entries

So that buffers don't grow indefinitely in memory.
This commit is contained in:
Přemysl Eric Janouch 2015-07-15 23:05:34 +02:00
parent bcbbdbc4bc
commit 6351ff387e
1 changed files with 11 additions and 0 deletions

View File

@ -82,6 +82,9 @@ enum
/// Some arbitrary limit for the history file /// Some arbitrary limit for the history file
#define HISTORY_LIMIT 10000 #define HISTORY_LIMIT 10000
/// How many lines of backlog to store in memory
#define BACKLOG_LIMIT 1000
/// Characters that separate words /// Characters that separate words
#define WORD_BREAKING_CHARS " \f\n\r\t\v" #define WORD_BREAKING_CHARS " \f\n\r\t\v"
@ -2725,6 +2728,14 @@ log_formatter (struct app_context *ctx,
if (!buffer) if (!buffer)
buffer = ctx->global_buffer; buffer = ctx->global_buffer;
if (buffer->lines_count >= BACKLOG_LIMIT)
{
struct buffer_line *popped = buffer->lines;
LIST_UNLINK_WITH_TAIL (buffer->lines, buffer->lines_tail, popped);
buffer_line_destroy (popped);
buffer->lines_count--;
}
struct buffer_line *line = buffer_line_new (); struct buffer_line *line = buffer_line_new ();
line->flags = flags; line->flags = flags;
line->when = time (NULL); line->when = time (NULL);