diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-05-11 13:01:36 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-05-11 13:01:36 +0000 |
commit | b936115ed6f0f9e2f86a9c000a98abf5552af7e9 (patch) | |
tree | db8a1e0c70860c6797338f2e3ad873f29b4dedc4 /parse.y | |
parent | 59630683d65f3e18b8ad79bbca595a8133981cca (diff) |
fix potential memory leaks
* parse.y (primary, new_args_tail, local_tbl): keep the order;
allocate an empty imemo first then xmalloc, to get rid of
potential memory leak when allocation imemo failed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -278,6 +278,9 @@ struct parser_params { #endif }; +#define new_tmpbuf() \ + (rb_imemo_tmpbuf_t *)add_mark_object(p, rb_imemo_tmpbuf_auto_free_pointer(NULL)) + #define intern_cstr(n,l,en) rb_intern3(n,l,en) #define STR_NEW(ptr,len) rb_enc_str_new((ptr),(len),p->enc) @@ -2511,9 +2514,10 @@ primary : literal ID id = internal_id(p); NODE *m = NEW_ARGS_AUX(0, 0, &NULL_LOC); NODE *args, *scope, *internal_var = NEW_DVAR(id, &@2); + rb_imemo_tmpbuf_t *tmpbuf = new_tmpbuf(); ID *tbl = ALLOC_N(ID, 2); tbl[0] = 1 /* length of local var table */; tbl[1] = id /* internal id */; - add_mark_object(p, rb_imemo_tmpbuf_auto_free_pointer(tbl)); + tmpbuf->ptr = (VALUE *)tbl; switch (nd_type($2)) { case NODE_LASGN: @@ -9994,9 +9998,10 @@ new_args_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, ID block, int saved_line = p->ruby_sourceline; struct rb_args_info *args; NODE *node; + rb_imemo_tmpbuf_t *tmpbuf = new_tmpbuf(); args = ZALLOC(struct rb_args_info); - add_mark_object(p, rb_imemo_tmpbuf_auto_free_pointer(args)); + tmpbuf->ptr = (VALUE *)args; node = NEW_NODE(NODE_ARGS, 0, 0, args, &NULL_LOC); if (p->error_p) return node; @@ -10344,9 +10349,11 @@ local_tbl(struct parser_params *p) int cnt = cnt_args + cnt_vars; int i, j; ID *buf; + rb_imemo_tmpbuf_t *tmpbuf = new_tmpbuf(); if (cnt <= 0) return 0; buf = ALLOC_N(ID, cnt + 1); + tmpbuf->ptr = (void *)buf; MEMCPY(buf+1, p->lvtbl->args->tbl, ID, cnt_args); /* remove IDs duplicated to warn shadowing */ for (i = 0, j = cnt_args+1; i < cnt_vars; ++i) { @@ -10355,11 +10362,9 @@ local_tbl(struct parser_params *p) buf[j++] = id; } } - if (--j < cnt) REALLOC_N(buf, ID, (cnt = j) + 1); + if (--j < cnt) tmpbuf->ptr = (void *)REALLOC_N(buf, ID, (cnt = j) + 1); buf[0] = cnt; - add_mark_object(p, rb_imemo_tmpbuf_auto_free_pointer(buf)); - return buf; } #endif |