ruby-changes:12821
From: nobu <ko1@a...>
Date: Sun, 16 Aug 2009 10:45:40 +0900 (JST)
Subject: [ruby-changes:12821] Ruby:r24550 (trunk): * regparse.c (parse_char_class, parse_exp, parse_branch),
nobu 2009-08-16 10:45:18 +0900 (Sun, 16 Aug 2009) New Revision: 24550 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24550 Log: * 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]. Modified files: trunk/ChangeLog trunk/regparse.c Index: regparse.c =================================================================== --- regparse.c (revision 24549) +++ regparse.c (revision 24550) @@ -1,3 +1,4 @@ +/* -*- mode:c; c-file-style:"gnu" -*- */ /********************************************************************** regparse.c - Oniguruma (regular expression library) **********************************************************************/ @@ -4454,12 +4455,11 @@ 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ } goto re_entry; } + + err: + onig_node_free(*np); } return r; @@ -5503,7 +5505,10 @@ 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 @@ *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 @@ 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: Index: ChangeLog =================================================================== --- ChangeLog (revision 24549) +++ ChangeLog (revision 24550) @@ -1,3 +1,9 @@ +Sun Aug 16 10:45:10 2009 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * vm.c (vm_backtrace_each, vm_backtrace_push), -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/