fix alloc vs copy_term and leak

This commit is contained in:
Vitor Santos Costa 2018-09-12 12:02:42 +01:00
parent 059c406fd9
commit 724dfee44a
3 changed files with 15 additions and 7 deletions

View File

@ -597,6 +597,7 @@ yap_error_descriptor_t *Yap_popErrorContext(bool mdnew, bool pass) {
memmove(ep, e, sizeof(*e)); memmove(ep, e, sizeof(*e));
ep->top_error = epp; ep->top_error = epp;
} }
free(e);
return LOCAL_ActiveError; return LOCAL_ActiveError;
} }
/** /**

View File

@ -352,9 +352,9 @@ static inline void clean_dirty_tr(tr_fr_ptr TR0 USES_REGS) {
} }
#define expand_stack(S0,SP,SF,TYPE) \ #define expand_stack(S0,SP,SF,TYPE) \
size_t sz = SF-S0, used = SP-S0; \ { size_t sz = SF-S0, used = SP-S0; \
S0 = Realloc(S0, (1024+sz)*sizeof(TYPE) PASS_REGS); \ S0 = Realloc(S0, (1024+sz)*sizeof(TYPE) PASS_REGS); \
SP = S0+used; SF = S0+sz; SP = S0+used; SF = S0+sz; }
static int copy_complex_term(register CELL *pt0, register CELL *pt0_end, static int copy_complex_term(register CELL *pt0, register CELL *pt0_end,
int share, int copy_att_vars, CELL *ptf, int share, int copy_att_vars, CELL *ptf,
@ -502,7 +502,7 @@ loop:
ptf++; ptf++;
/* store the terms to visit */ /* store the terms to visit */
#ifdef RATIONAL_TREES #ifdef RATIONAL_TREES
if (to_visit + 1 >= to_visit_max) { if (to_visit + 32 >= to_visit_max) {
expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame); expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
} }
to_visit->start_cp = pt0; to_visit->start_cp = pt0;

View File

@ -176,14 +176,21 @@ void *MallocAtLevel(size_t sz, int atL USES_REGS) {
} }
void *Realloc(void *pt, size_t sz USES_REGS) { void *Realloc(void *pt, size_t sz USES_REGS) {
sz += sizeof(struct mblock);
struct mblock *old = pt, *o; struct mblock *old = pt, *o;
old--; old--;
release_block(old); sz = ALIGN_BY_TYPE(sz + sizeof(struct mblock), CELL);
o = realloc(old, sz); o = realloc(old, sz);
if (o->next) {
o->next->prev = o;
} else {
LOCAL_TextBuffer->last[o->lvl] = o;
}
if (o->prev) {
o->prev->next = o;
} else {
LOCAL_TextBuffer->first[o->lvl] = o;
}
o->sz = sz; o->sz = sz;
insert_block(o);
return o + 1; return o + 1;
} }