Skip to content

Commit

Permalink
- fix mrbc_filename leak; cxt->filename would not be freed until the …
Browse files Browse the repository at this point in the history
…state is closed.
  • Loading branch information
nozomiS committed Sep 4, 2016
1 parent 22dc84f commit 068b46d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mrbgems/mruby-compiler/core/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -5540,6 +5540,7 @@ mrbc_context_new(mrb_state *mrb)
MRB_API void
mrbc_context_free(mrb_state *mrb, mrbc_context *cxt)
{
mrb_free(mrb, cxt->filename);
mrb_free(mrb, cxt->syms);
mrb_free(mrb, cxt);
}
Expand All @@ -5549,9 +5550,12 @@ mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s)
{
if (s) {
int len = strlen(s);
char *p = (char *)mrb_alloca(mrb, len + 1);
char *p = (char *)mrb_malloc(mrb, len + 1);

memcpy(p, s, len + 1);
if (c->filename) {
mrb_free(mrb, c->filename);
}
c->filename = p;
}
return c->filename;
Expand Down

0 comments on commit 068b46d

Please sign in to comment.