From 2229fd91f7230ae7068814ae029b733945852eb1 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Tue, 2 Apr 2024 09:17:06 +0200 Subject: Kernel: Fix some memory leaks --- kernel/lib/list.c | 11 ++++++----- kernel/lib/list.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'kernel/lib') diff --git a/kernel/lib/list.c b/kernel/lib/list.c index 9cdcd01..d189c86 100644 --- a/kernel/lib/list.c +++ b/kernel/lib/list.c @@ -4,7 +4,8 @@ int list_init(struct list *list) { // TODO: Make it dynamic - list->entries = kmalloc(sizeof(void *) * 100); + list->capacity = 5; + list->entries = kmalloc(sizeof(void *) * list->capacity); if (!list->entries) { return 0; } @@ -17,13 +18,13 @@ void list_reset(struct list *list) { } int list_add(struct list *list, void *entry, int *index) { - if (list->tail_index > 100 - 1) { - kprintf("Error: list has run out of space\n"); - assert(0); + if (list->tail_index + 1 >= list->capacity) { + list->capacity += 25; + list->entries = krealloc(list->entries, sizeof(void *) * list->capacity); } list->tail_index++; list->entries[list->tail_index] = entry; - if(index) { + if (index) { *index = list->tail_index; } return 1; diff --git a/kernel/lib/list.h b/kernel/lib/list.h index 6ab9e0b..b7085cd 100644 --- a/kernel/lib/list.h +++ b/kernel/lib/list.h @@ -2,6 +2,7 @@ #define LIST_H struct list { void **entries; + int capacity; int tail_index; }; -- cgit v1.2.3