summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-15 23:05:34 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-15 23:05:45 +0200
commit6351ff387e74cb24c89eba1be104cc716e2dc371 (patch)
treecce7278db7898844b03bf8a7c60497bcff80a19b /degesch.c
parentbcbbdbc4bcc5f82cef0d829fbf8beb4415c4f3c8 (diff)
downloadxK-6351ff387e74cb24c89eba1be104cc716e2dc371.tar.gz
xK-6351ff387e74cb24c89eba1be104cc716e2dc371.tar.xz
xK-6351ff387e74cb24c89eba1be104cc716e2dc371.zip
degesch: set a limit on backlog entries
So that buffers don't grow indefinitely in memory.
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/degesch.c b/degesch.c
index 5ac89c1..1ff89c9 100644
--- a/degesch.c
+++ b/degesch.c
@@ -82,6 +82,9 @@ enum
/// Some arbitrary limit for the history file
#define HISTORY_LIMIT 10000
+/// How many lines of backlog to store in memory
+#define BACKLOG_LIMIT 1000
+
/// Characters that separate words
#define WORD_BREAKING_CHARS " \f\n\r\t\v"
@@ -2725,6 +2728,14 @@ log_formatter (struct app_context *ctx,
if (!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 ();
line->flags = flags;
line->when = time (NULL);