diff --git a/src/bif_functions.c b/src/bif_functions.c index 098f1d1a..24caba42 100644 --- a/src/bif_functions.c +++ b/src/bif_functions.c @@ -23,7 +23,7 @@ } \ if (errno == ENOMEM) \ return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory"); \ - q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); \ + q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; \ q->accum.val_bigint->refcnt = 0; \ } @@ -39,7 +39,7 @@ } \ if (errno == ENOMEM) \ return throw_error(q, p1, q->st.curr_frame, "resource_error", "memory"); \ - q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); \ + q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; \ q->accum.val_bigint->refcnt = 0; \ } @@ -54,7 +54,7 @@ if (mp_rat_init_copy(&q->accum.val_bigint->irat, &q->tmp_irat) == MP_MEMORY) {\ return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory"); \ } \ - q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); \ + q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; \ q->accum.val_bigint->refcnt = 0; \ } else { \ q->accum.tag = TAG_INTEGER; \ @@ -64,7 +64,7 @@ if (mp_int_init_copy(&q->accum.val_bigint->ival, &q->tmp_irat.num) == MP_MEMORY) {\ return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory"); \ } \ - q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); \ + q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; \ q->accum.val_bigint->refcnt = 0; \ } \ if (errno == ENOMEM) \ @@ -512,7 +512,7 @@ static bool bif_numerator_1(query *q) mp_int_init_copy(&q->accum.val_bigint->ival, &p1.val_bigint->irat.num); if (errno == ENOMEM) return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory"); - q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); + q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; q->accum.val_bigint->refcnt = 0; return true; } @@ -540,7 +540,7 @@ static bool bif_denominator_1(query *q) mp_int_init_copy(&q->accum.val_bigint->ival, &p1.val_bigint->irat.den); if (errno == ENOMEM) return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory"); - q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); + q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; q->accum.val_bigint->refcnt = 0; return true; } diff --git a/src/bif_predicates.c b/src/bif_predicates.c index d1052732..9405b4b2 100644 --- a/src/bif_predicates.c +++ b/src/bif_predicates.c @@ -4761,7 +4761,7 @@ static bool bif_hex_chars_2(query *q) check_heap_error(tmp.val_bigint); tmp.val_bigint->refcnt = 1; mp_int_init_copy(&tmp.val_bigint->ival, &v2); - tmp.flags |= ((FLAG_MANAGED | FLAG_INT_BIG) | FLAG_INT_BIG); + tmp.flags |= FLAG_INT_BIG | FLAG_MANAGED | FLAG_INT_BIG; } else { make_uint(&tmp, (unsigned long long)val); } @@ -4816,7 +4816,7 @@ static bool bif_octal_chars_2(query *q) check_heap_error(tmp.val_bigint); tmp.val_bigint->refcnt = 1; mp_int_init_copy(&tmp.val_bigint->ival, &v2); - tmp.flags |= (FLAG_MANAGED | FLAG_INT_BIG); + tmp.flags |= FLAG_INT_BIG | FLAG_MANAGED; } else { make_uint(&tmp, (unsigned long long)val); } diff --git a/src/parser.c b/src/parser.c index 17f6817f..17417703 100644 --- a/src/parser.c +++ b/src/parser.c @@ -2606,7 +2606,7 @@ static bool parse_number(parser *p, const char **srcptr, bool neg) p->v.val_bigint->refcnt = 1; mp_int_init_copy(&p->v.val_bigint->ival, &v2); if (neg) p->v.val_bigint->ival.sign = MP_NEG; - p->v.flags |= FLAG_INT_BIG; + p->v.flags |= FLAG_INT_BIG | FLAG_MANAGED; } else { set_smallint(&p->v, val); if (neg) p->v.val_int = -p->v.val_int; @@ -2629,7 +2629,7 @@ static bool parse_number(parser *p, const char **srcptr, bool neg) p->v.val_bigint->refcnt = 1; mp_int_init_copy(&p->v.val_bigint->ival, &v2); if (neg) p->v.val_bigint->ival.sign = MP_NEG; - p->v.flags |= FLAG_INT_BIG; + p->v.flags |= FLAG_INT_BIG | FLAG_MANAGED; } else { set_smallint(&p->v, val); if (neg) p->v.val_int = -p->v.val_int; @@ -2652,7 +2652,7 @@ static bool parse_number(parser *p, const char **srcptr, bool neg) p->v.val_bigint->refcnt = 1; mp_int_init_copy(&p->v.val_bigint->ival, &v2); if (neg) p->v.val_bigint->ival.sign = MP_NEG; - p->v.flags |= FLAG_INT_BIG; + p->v.flags |= FLAG_INT_BIG | FLAG_MANAGED; } else { set_smallint(&p->v, val); if (neg) p->v.val_int = -p->v.val_int; @@ -2712,7 +2712,7 @@ static bool parse_number(parser *p, const char **srcptr, bool neg) p->v.val_bigint->refcnt = 1; mp_int_init_copy(&p->v.val_bigint->ival, &v2); if (neg) p->v.val_bigint->ival.sign = MP_NEG; - p->v.flags |= FLAG_INT_BIG; + p->v.flags |= FLAG_INT_BIG | FLAG_MANAGED; } else { set_smallint(&p->v, val); if (neg) p->v.val_int = -p->v.val_int; diff --git a/src/query.c b/src/query.c index c3245e7d..625605ad 100644 --- a/src/query.c +++ b/src/query.c @@ -1813,6 +1813,16 @@ void query_destroy(query *q) free(save); } + while (q->st.tp > 0) { + const trail *tr = q->trails + --q->st.tp; + const frame *f = GET_FRAME(tr->var_ctx); + slot *e = GET_SLOT(f, tr->var_nbr); + cell *c = &e->c; + unshare_cell(c); + c->tag = TAG_EMPTY; + c->attrs = tr->attrs; + } + for (int i = 0; i < MAX_QUEUES; i++) free(q->queue[i]);