diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-30 06:54:25 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-30 06:54:25 +0000 |
commit | 6ada14922f6ff406f17a34192132ec17bce75ce6 (patch) | |
tree | cadc1ac351a0386268f4f974ec1515eeca2ddd5a /ext/strscan | |
parent | 34e157478be78a95a3480f7bb145d639da1c943b (diff) | |
download | ruby-6ada14922f6ff406f17a34192132ec17bce75ce6.tar.gz |
* ext/openssl/ossl_config.c (Init_ossl_config): memory leak fixed.
a patch <shinichiro.hamaji at gmail.com> in [ruby-dev:35880].
* ext/openssl/ossl_x509ext.c (ossl_x509ext_set_value): ditto.
* ext/strscan/strscan.c (strscan_do_scan): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/strscan')
-rw-r--r-- | ext/strscan/strscan.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c index 622bfae214..6f05ec3666 100644 --- a/ext/strscan/strscan.c +++ b/ext/strscan/strscan.c @@ -407,6 +407,7 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly) struct strscanner *p; regex_t *re; int ret; + int tmpreg; Check_Type(regex, T_REGEXP); GET_SCANNER(self, p); @@ -416,6 +417,9 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly) return Qnil; } re = rb_reg_prepare_re(regex, p->str); + tmpreg = re != RREGEXP(regex)->ptr; + if (!tmpreg) RREGEXP(regex)->usecnt++; + if (headonly) { ret = onig_match(re, (UChar* )CURPTR(p), (UChar* )(CURPTR(p) + S_RESTLEN(p)), @@ -427,6 +431,16 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly) (UChar* )CURPTR(p), (UChar* )(CURPTR(p) + S_RESTLEN(p)), &(p->regs), ONIG_OPTION_NONE); } + if (!tmpreg) RREGEXP(re)->usecnt--; + if (tmpreg) { + if (RREGEXP(regex)->usecnt) { + onig_free(re); + } + else { + onig_free(RREGEXP(regex)->ptr); + RREGEXP(regex)->ptr = re; + } + } if (ret == -2) rb_raise(ScanError, "regexp buffer overflow"); if (ret < 0) { |