1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* regparse.c (parse_char_class, parse_exp, parse_branch),

(parse_subexp): fixed memory leak.  a patch from Ralf Junker
  <ralfjunker AT gmx.de> at [ruby-core:24921].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-08-16 01:45:18 +00:00
parent cd48eb8fd5
commit 2318bef1de
2 changed files with 41 additions and 25 deletions

View file

@ -1,3 +1,9 @@
Sun Aug 16 10:45:10 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* regparse.c (parse_char_class, parse_exp, parse_branch),
(parse_subexp): fixed memory leak. a patch from Ralf Junker
<ralfjunker AT gmx.de> at [ruby-core:24921].
Sun Aug 16 10:38:23 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm.c (vm_backtrace_each, vm_backtrace_push),

View file

@ -1,3 +1,4 @@
/* -*- mode:c; c-file-style:"gnu" -*- */
/**********************************************************************
regparse.c - Oniguruma (regular expression library)
**********************************************************************/
@ -4454,12 +4455,11 @@ parse_char_class(Node** np, OnigToken* tok, UChar** src, UChar* end,
CClassNode* acc;
r = parse_char_class(&anode, tok, &p, end, env);
if (r != 0) goto cc_open_err;
acc = NCCLASS(anode);
r = or_cclass(cc, acc, env);
if (r == 0) {
acc = NCCLASS(anode);
r = or_cclass(cc, acc, env);
}
onig_node_free(anode);
cc_open_err:
if (r != 0) goto err;
}
break;
@ -5105,9 +5105,8 @@ parse_exp(Node** np, OnigToken* tok, int term,
case TK_ALT:
case TK_EOT:
end_of_token:
*np = node_new_empty();
return tok->type;
break;
*np = node_new_empty();
return tok->type;
case TK_SUBEXP_OPEN:
r = parse_enclose(np, tok, TK_SUBEXP_CLOSE, src, end, env);
@ -5119,10 +5118,10 @@ parse_exp(Node** np, OnigToken* tok, int term,
env->option = NENCLOSE(*np)->option;
r = fetch_token(tok, src, end, env);
if (r < 0) return r;
if (r < 0) goto err;
r = parse_subexp(&target, tok, term, src, end, env);
env->option = prev;
if (r < 0) return r;
if (r < 0) goto err;
NENCLOSE(*np)->target = target;
return tok->type;
}
@ -5144,11 +5143,11 @@ parse_exp(Node** np, OnigToken* tok, int term,
while (1) {
r = fetch_token(tok, src, end, env);
if (r < 0) return r;
if (r < 0) goto err;
if (r != TK_STRING) break;
r = onig_node_str_cat(*np, tok->backp, *src);
if (r < 0) return r;
if (r < 0) goto err;
}
string_end:
@ -5173,7 +5172,7 @@ parse_exp(Node** np, OnigToken* tok, int term,
}
r = fetch_token(tok, src, end, env);
if (r < 0) return r;
if (r < 0) goto err;
if (r != TK_RAW_BYTE) {
/* Don't use this, it is wrong for little endian encodings. */
#ifdef USE_PAD_TO_SHORT_BYTE_CHAR
@ -5191,7 +5190,7 @@ parse_exp(Node** np, OnigToken* tok, int term,
}
r = node_str_cat_char(*np, (UChar )tok->u.c);
if (r < 0) return r;
if (r < 0) goto err;
len++;
}
@ -5352,7 +5351,7 @@ parse_exp(Node** np, OnigToken* tok, int term,
i_apply_case_fold, &iarg);
if (r != 0) {
onig_node_free(iarg.alt_root);
return r;
goto err;
}
if (IS_NOT_NULL(iarg.alt_root)) {
Node* work = onig_node_new_alt(*np, iarg.alt_root);
@ -5437,7 +5436,7 @@ parse_exp(Node** np, OnigToken* tok, int term,
re_entry:
r = fetch_token(tok, src, end, env);
if (r < 0) return r;
if (r < 0) goto err;
repeat:
if (r == TK_OP_REPEAT || r == TK_INTERVAL) {
@ -5449,7 +5448,7 @@ parse_exp(Node** np, OnigToken* tok, int term,
CHECK_NULL_RETURN_MEMERR(qn);
NQTFR(qn)->greedy = tok->u.repeat.greedy;
r = set_quantifier(qn, *targetp, group, env);
if (r < 0) return r;
if (r < 0) goto err;
if (tok->u.repeat.possessive != 0) {
Node* en;
@ -5479,6 +5478,9 @@ parse_exp(Node** np, OnigToken* tok, int term,
}
goto re_entry;
}
err:
onig_node_free(*np);
}
return r;
@ -5503,7 +5505,10 @@ parse_branch(Node** top, OnigToken* tok, int term,
headp = &(NCDR(*top));
while (r != TK_EOT && r != term && r != TK_ALT) {
r = parse_exp(&node, tok, term, src, end, env);
if (r < 0) return r;
if (r < 0) {
onig_node_free(*top);
return r;
}
if (NTYPE(node) == NT_LIST) {
*headp = node;
@ -5530,10 +5535,7 @@ parse_subexp(Node** top, OnigToken* tok, int term,
*top = NULL;
r = parse_branch(&node, tok, term, src, end, env);
if (r < 0) {
onig_node_free(node);
return r;
}
if (r < 0) return r;
if (r == term) {
*top = node;
@ -5543,16 +5545,24 @@ parse_subexp(Node** top, OnigToken* tok, int term,
headp = &(NCDR(*top));
while (r == TK_ALT) {
r = fetch_token(tok, src, end, env);
if (r < 0) return r;
if (r < 0) {
onig_node_free(*top);
return r;
}
r = parse_branch(&node, tok, term, src, end, env);
if (r < 0) return r;
if (r < 0) {
onig_node_free(*top);
return r;
}
*headp = onig_node_new_alt(node, NULL);
headp = &(NCDR(*headp));
}
if (tok->type != (enum TokenSyms )term)
if (tok->type != (enum TokenSyms )term) {
onig_node_free(*top);
goto err;
}
}
else {
err: