]> git.ipfire.org Git - pakfire.git/commitdiff
log buffer: Make the dequeue operation zero-copy
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jan 2025 15:46:49 +0000 (15:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jan 2025 15:46:49 +0000 (15:46 +0000)
Since we already have a copy of the data which will no longer need, we
can keep our internal pointer and just skip freeing it.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/log_buffer.c

index 91de15532424526658e9b483dfe467d47aba5046..0e592f52f490f0f888919e393ec062a8b8fcfad0 100644 (file)
@@ -168,9 +168,10 @@ int pakfire_log_buffer_dequeue(struct pakfire_log_buffer* buffer, int* priority,
        *priority = l->priority;
 
        // Return the line
-       *line = strndup(l->line, l->length);
-       if (!*line)
-               return -errno;
+       *line = l->line;
+
+       // Reset so we won't free the buffer
+       l->line = NULL;
 
        // Return the length
        if (length)