diff --git a/cobc/codegen.c b/cobc/codegen.c index 68bb88c94..056018cb7 100644 --- a/cobc/codegen.c +++ b/cobc/codegen.c @@ -12872,15 +12872,15 @@ output_internal_function (struct cb_program *prog, cb_tree parameter_list) if (prog->flag_inspect_used) { output_line ("if (inspect_st != NULL)"); - output_line ("\tcob_free (inspect_st);"); + output_line ("\tcob_inspect_free (inspect_st);"); } if (prog->flag_string_used) { output_line ("if (string_st != NULL)"); - output_line ("\tcob_free (string_st);"); + output_line ("\tcob_string_free (string_st);"); } if (prog->flag_unstring_used) { output_line ("if (unstring_st != NULL)"); - output_line ("\tcob_free (unstring_st);"); + output_line ("\tcob_unstring_free (unstring_st);"); } if (prog->flag_main) { diff --git a/libcob/common.h b/libcob/common.h index d8c757abc..86e097b8c 100644 --- a/libcob/common.h +++ b/libcob/common.h @@ -1954,12 +1954,14 @@ COB_EXPIMP void cob_inspect_trailing_r (cob_inspect_state *, cob_field *, cob_fi COB_EXPIMP void cob_inspect_converting_r (cob_inspect_state *, const cob_field *, const cob_field *); COB_EXPIMP void cob_inspect_translating_r (cob_inspect_state *, const unsigned char *); COB_EXPIMP void cob_inspect_finish_r (cob_inspect_state *); +COB_EXPIMP void cob_inspect_free (cob_inspect_state *); /* Thread-safe string */ COB_EXPIMP void cob_string_init_r (cob_string_state **, cob_field *, cob_field *); COB_EXPIMP void cob_string_delimited_r (cob_string_state *, cob_field *); COB_EXPIMP void cob_string_append_r (cob_string_state *, cob_field *); COB_EXPIMP void cob_string_finish_r (cob_string_state *); +COB_EXPIMP void cob_string_free (cob_string_state *); /* Thread-safe unstring */ COB_EXPIMP void cob_unstring_init_r (cob_unstring_state **, cob_field *, cob_field *, const size_t); @@ -1967,6 +1969,7 @@ COB_EXPIMP void cob_unstring_delimited_r (cob_unstring_state *, cob_field *, con COB_EXPIMP void cob_unstring_into_r (cob_unstring_state *, cob_field *, cob_field *, cob_field *); COB_EXPIMP void cob_unstring_tallying_r (cob_unstring_state *, cob_field *); COB_EXPIMP void cob_unstring_finish_r (cob_unstring_state *); +COB_EXPIMP void cob_unstring_free (cob_unstring_state *); /* Compat-only functions for old programs */ COB_EXPIMP void cob_inspect_init (cob_field *, const cob_u32_t); diff --git a/libcob/strings.c b/libcob/strings.c index 66e5f1ddc..6f3bfdb54 100644 --- a/libcob/strings.c +++ b/libcob/strings.c @@ -1301,31 +1301,50 @@ cob_unstring_finish (void) /* Initialization/Termination */ void -cob_exit_strings () +cob_inspect_free (struct cob_inspect_state *st) { - struct cob_inspect_state *sti = share_inspect_state; - struct cob_unstring_state *stu = share_unstring_state; - - if (sti != NULL) { - if (sti->mark) { - cob_free (sti->mark); - sti->mark = NULL; + if (st != NULL) { + if (st->mark) { + cob_free (st->mark); + st->mark = NULL; } - sti->mark_size = sti->mark_min = sti->mark_max = 0; - if (sti->repdata) { - cob_free (sti->repdata); - sti->repdata = NULL; + st->mark_size = st->mark_min = st->mark_max = 0; + if (st->repdata) { + cob_free (st->repdata); + st->repdata = NULL; } - sti->repdata_size = 0; + st->repdata_size = 0; } +} + +void +cob_string_free (struct cob_string_state *st) +{ + cob_free (st->dst); + cob_free (st->ptr); + cob_free (st->dlm); +} - if (stu != NULL) { - if (stu->dlm_list) { - cob_free (stu->dlm_list); - stu->dlm_list = NULL; +void +cob_unstring_free (struct cob_unstring_state *st) +{ + if (st != NULL) { + if (st->dlm_list) { + cob_free (st->dlm_list); + st->dlm_list = NULL; + st->dlm_list_size = 0; } - stu->dlm_list_size = 0; } +} + +void +cob_exit_strings () +{ + struct cob_inspect_state *sti = share_inspect_state; + struct cob_unstring_state *stu = share_unstring_state; + + cob_inspect_free (sti); + cob_unstring_free (stu); if (figurative_ptr) { cob_free (figurative_ptr);