scriptblock: fix memory leaks

This commit is contained in:
2026-05-30 19:51:52 +01:00
parent 3b39f794f9
commit a30e76e525
+9 -10
View File
@@ -18,21 +18,20 @@ struct bshell_scriptblock_p {
fx_namemap b_strings;
};
static fx_status pool_destroy(void *p)
static void cache_entry_cleanup(fx_namemap_entry *e)
{
fx_value_unset(p);
return FX_SUCCESS;
struct string_cache_entry *entry
= fx_unbox(struct string_cache_entry, e, e_entry);
free(entry);
}
static fx_vector_ops pool_ops = {
.v_destroy = pool_destroy,
};
static void scriptblock_fini(fx_object *obj, void *priv)
{
struct bshell_scriptblock_p *block = priv;
fx_vector_destroy(block->b_pool, &pool_ops);
fx_namemap_cleanup(&block->b_strings, cache_entry_cleanup);
fx_value_unset_array(block->b_pool.items, block->b_pool.count);
fx_vector_destroy(block->b_pool, NULL);
fx_vector_destroy(block->b_text, NULL);
}
@@ -125,7 +124,7 @@ static unsigned long scriptblock_add_pool_value(
fx_value *value)
{
unsigned long id = block->b_pool.count;
fx_value *slot = fx_vector_emplace_back(block->b_pool, &pool_ops);
fx_value *slot = fx_vector_emplace_back(block->b_pool, NULL);
if (!slot) {
return (unsigned long)-1;
}
@@ -176,7 +175,7 @@ static unsigned long scriptblock_get_string(
}
unsigned long index = block->b_pool.count;
fx_value *slot = fx_vector_emplace_back(block->b_pool, &pool_ops);
fx_value *slot = fx_vector_emplace_back(block->b_pool, NULL);
if (!slot) {
goto cleanup;
}