[C] malloc->calloc + conditions merged in free_state_*

This commit is contained in:
Arnaud DABY-SEESARAM 2022-12-20 16:52:59 +01:00
parent a673c447e3
commit 8c3e3d1eac
2 changed files with 11 additions and 8 deletions

View File

@ -237,7 +237,7 @@ let cp_init_aux_nodes fmt (node, h) =
| Some n ->
begin
Format.fprintf fmt "%a\t\tif(!state->is_reset) {\n\
\t\t\tstate->aux_states[%d] = malloc (sizeof (%s));\n\
\t\t\tstate->aux_states[%d] = calloc (1, sizeof (%s));\n\
\t\t}\n\
\t\t((%s*)(state->aux_states[%d]))->is_init = true;\n\
\t\t((%s*)(state->aux_states[%d]))->is_reset = state->is_reset;\n"

View File

@ -91,13 +91,16 @@ let cp_state_frees fmt (iprog, sts) =
| None -> ()
| Some callee_name ->
let callee_st = Hashtbl.find sts callee_name in
if callee_st.nt_count_app > 0 then
Format.fprintf fmt "\tif (st->aux_states[%d])\n\
\t\tfree_state_%s((t_state_%s*)(st->aux_states[%d]));\n"
idx callee_name callee_name idx;
Format.fprintf fmt "\tif (st->aux_states[%d])\n\
\t\tfree(st->aux_states[%d]);\n%a"
idx idx cp_free_aux (i+1, caller_name)
if callee_st.nt_count_app > 0
then
Format.fprintf fmt "\tif (st->aux_states[%d]) {\n\
\t\tfree_state_%s((t_state_%s*)(st->aux_states[%d]));\n\
\t\tfree (st->aux_state[%d]);\n\t}\n%a"
idx callee_name callee_name idx
idx cp_free_aux (i+1, caller_name)
else Format.fprintf fmt "\tif (st->aux_states[%d])\n\
\t\tfree(st->aux_states[%d]);\n%a"
idx idx cp_free_aux (i+1, caller_name)
in
Hashtbl.iter
(fun node_name node_st ->