runtime: fix memory leaks
This commit is contained in:
@@ -21,6 +21,10 @@ struct bshell_runtime *bshell_runtime_create(void)
|
||||
|
||||
void bshell_runtime_destroy(struct bshell_runtime *rt)
|
||||
{
|
||||
while (!fx_queue_empty(&rt->rt_scope)) {
|
||||
runtime_pop_scope(rt);
|
||||
}
|
||||
|
||||
fx_hashtable_unref(rt->rt_aliases);
|
||||
free(rt);
|
||||
}
|
||||
@@ -63,6 +67,31 @@ bshell_variable *bshell_runtime_define_var(
|
||||
return var;
|
||||
}
|
||||
|
||||
enum bshell_status bshell_runtime_define_function(
|
||||
struct bshell_runtime *rt,
|
||||
bshell_function *func)
|
||||
{
|
||||
struct bshell_runtime_scope *scope = runtime_get_scope(rt);
|
||||
if (!scope) {
|
||||
return BSHELL_ERR_BAD_STATE;
|
||||
}
|
||||
|
||||
fx_string *name
|
||||
= fx_string_create_from_cstr(bshell_function_get_name(func));
|
||||
if (!name) {
|
||||
return BSHELL_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
fx_string_transform_lowercase(name);
|
||||
fx_hashtable_put(
|
||||
scope->s_functions,
|
||||
&FX_VALUE_OBJECT(name),
|
||||
&FX_VALUE_OBJECT(func));
|
||||
fx_string_unref(name);
|
||||
|
||||
return BSHELL_SUCCESS;
|
||||
}
|
||||
|
||||
bshell_command *bshell_runtime_find_command(
|
||||
struct bshell_runtime *rt,
|
||||
const char *callable_name)
|
||||
|
||||
Reference in New Issue
Block a user