summaryrefslogtreecommitdiff
path: root/kernel/lib/list.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-02 09:17:06 +0200
committerAnton Kling <anton@kling.gg>2024-04-02 09:39:03 +0200
commit2229fd91f7230ae7068814ae029b733945852eb1 (patch)
tree416487f8c66c389c57dee465f648362ca59b8f23 /kernel/lib/list.c
parent7eceb43433634ee253507208baf1d8298b40e377 (diff)
Kernel: Fix some memory leaks
Diffstat (limited to 'kernel/lib/list.c')
-rw-r--r--kernel/lib/list.c11
1 files changed, 6 insertions, 5 deletions
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;