Skip to content

Commit

Permalink
Fix allocation/deallocation of T->szirmcode
Browse files Browse the repository at this point in the history
This array was allocated too large (padded to REF_BASE) and was not
freed.
  • Loading branch information
lukego committed Aug 9, 2018
1 parent 5171334 commit 4782265
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lj_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2003,8 +2003,9 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
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
1 change: 1 addition & 0 deletions src/lj_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,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 4782265

Please sign in to comment.