Skip to content

Commit

Permalink
Merge pull request snabbco#183 from lukego/szirmcode-alloc-free
Browse files Browse the repository at this point in the history
Fix allocation/deallocation of T->szirmcode
  • Loading branch information
lukego authored Aug 9, 2018
2 parents 9056918 + 9959cb1 commit 9fac632
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lj_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1995,16 +1995,17 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
/* Setup initial state. Copy some fields to reduce indirections. */
as->J = J;
as->T = T;
J->curfinal = lj_trace_alloc(J->L, T); /* This copies the IR, too. */
J->curfinal = lj_trace_alloc(J->L, T); /* Copies IR and moves szirmcode. */
as->flags = J->flags;
as->loopref = J->loopref;
as->realign = NULL;
as->loopinv = 0;
as->parent = J->parent ? traceref(J, J->parent) : NULL;

/* Initialize mcode size of IR instructions array. */
T->szirmcode = lj_mem_new(J->L, (T->nins + 1) * sizeof(*T->szirmcode));
memset(T->szirmcode, 0, (T->nins + 1) * sizeof(*T->szirmcode));
/* +2 extra spaces for the last instruction and the trace header at [0]. */
T->szirmcode = lj_mem_new(J->L, (T->nins + 2 - REF_BIAS) * sizeof(*T->szirmcode));
memset(T->szirmcode, 0, (T->nins + 2 - REF_BIAS) * sizeof(*T->szirmcode));

/* Reserve MCode memory. */
as->mctop = origtop = lj_mcode_reserve(J, &as->mcbot);
Expand Down
2 changes: 2 additions & 0 deletions src/lj_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ GCtrace * lj_trace_alloc(lua_State *L, GCtrace *T)
T2->nk = T->nk;
T2->nsnap = T->nsnap;
T2->nsnapmap = T->nsnapmap;
T2->szirmcode = T->szirmcode;
memcpy(p, T->ir + T->nk, szins);
return T2;
}
Expand Down Expand Up @@ -136,6 +137,7 @@ void lj_trace_free(global_State *g, GCtrace *T)
lj_gdbjit_deltrace(J, T);
setgcrefnull(J->trace[T->traceno]);
}
lj_mem_free(g, T->szirmcode, (T->nins + 2 - REF_BIAS) * sizeof(*T->szirmcode));
lj_mem_free(g, T,
((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) +
T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry));
Expand Down

0 comments on commit 9fac632

Please sign in to comment.