diff options
author | Anton Kling <anton@kling.gg> | 2024-04-02 09:17:06 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-04-02 09:39:03 +0200 |
commit | 2229fd91f7230ae7068814ae029b733945852eb1 (patch) | |
tree | 416487f8c66c389c57dee465f648362ca59b8f23 /kernel/lib | |
parent | 7eceb43433634ee253507208baf1d8298b40e377 (diff) |
Kernel: Fix some memory leaks
Diffstat (limited to 'kernel/lib')
-rw-r--r-- | kernel/lib/list.c | 11 | ||||
-rw-r--r-- | kernel/lib/list.h | 1 |
2 files changed, 7 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; 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; }; |