diff options
author | Marvin Borner | 2023-02-18 01:00:46 +0100 |
---|---|---|
committer | Marvin Borner | 2023-02-18 01:00:46 +0100 |
commit | be5d819c903540419d162afda7fb16e8960233cc (patch) | |
tree | 3370749c14acb9b4e030aeb8048cc152706bfe90 /src/store.c | |
parent | ec5b8ff7352984f8b63b79995df15527bd7a9e70 (diff) |
Fixed more memory leaks
Doesn't seem to help much. I really need to sleep though so maybe i'm
just dumb
Diffstat (limited to 'src/store.c')
-rw-r--r-- | src/store.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/store.c b/src/store.c index 92d7099..784399a 100644 --- a/src/store.c +++ b/src/store.c @@ -2,6 +2,7 @@ * MIT License * * Copyright (c) 2020 Samuel Vogelsanger <vogelsangersamuel@gmail.com> + * Copyright (c) 2023 Marvin Borner <dev@marvinborner.de> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -247,11 +248,21 @@ static void iter_pop(struct store_iter *iterator); * definitions */ +extern void store_release_callback(void *data); + static void node_destroy(struct node *node) { DEBUG_NOTICE(" destroying " store_node_debug_fmt "@%p\n", store_node_debug_args(node), (void *)node); + // release boxes in node + if (node->ref_count == 0) { + for (unsigned i = 0; i < node->element_arity; ++i) { + struct kv kv = node->content[i]; + store_release_callback(kv.val); + } + } + // reference counting STORE_NODE_BRANCH_T *branches = (STORE_NODE_BRANCH_T *)STORE_NODE_BRANCHES(node); @@ -262,12 +273,21 @@ static void node_destroy(struct node *node) free(node); } +extern void store_acquire_callback(void *data); + // reference counting static inline struct node *store_node_acquire(const struct node *node) { if (node == &empty_node) return (struct node *)node; atomic_fetch_add((uint16_t *)&node->ref_count, 1u); + + // aqcuire boxes in node + for (unsigned i = 0; i < node->element_arity; ++i) { + struct kv kv = node->content[i]; + store_acquire_callback(kv.val); + } + return (struct node *)node; } @@ -898,6 +918,7 @@ static struct store *store_from(struct node *root, unsigned length, void store_destroy(struct store **store) { DEBUG_NOTICE("destroying store@%p\n", (void *)*store); + store_node_release((*store)->root); free(*store); *store = NULL; |