summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/openssl/ossl_config.c4
-rw-r--r--ext/openssl/ossl_x509ext.c1
-rw-r--r--ext/strscan/strscan.c14
3 files changed, 18 insertions, 1 deletions
diff --git a/ext/openssl/ossl_config.c b/ext/openssl/ossl_config.c
index baa573d4bb8..f305af47b28 100644
--- a/ext/openssl/ossl_config.c
+++ b/ext/openssl/ossl_config.c
@@ -443,8 +443,10 @@ Init_ossl_config()
eConfigError = rb_define_class_under(mOSSL, "ConfigError", eOSSLError);
cConfig = rb_define_class_under(mOSSL, "Config", rb_cObject);
+ const char *default_config_file = CONF_get1_default_config_file();
rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
- rb_str_new2(CONF_get1_default_config_file()));
+ rb_str_new2(default_config_file));
+ OPENSSL_free(default_config_file);
rb_include_module(cConfig, rb_mEnumerable);
rb_define_singleton_method(cConfig, "parse", ossl_config_s_parse, 1);
rb_define_alias(CLASS_OF(cConfig), "load", "new");
diff --git a/ext/openssl/ossl_x509ext.c b/ext/openssl/ossl_x509ext.c
index f08006f34be..64867039f2b 100644
--- a/ext/openssl/ossl_x509ext.c
+++ b/ext/openssl/ossl_x509ext.c
@@ -333,6 +333,7 @@ ossl_x509ext_set_value(VALUE self, VALUE data)
ASN1_OCTET_STRING_free(asn1s);
ossl_raise(eX509ExtError, NULL);
}
+ free(s);
GetX509Ext(self, ext);
X509_EXTENSION_set_data(ext, asn1s);
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c
index 622bfae2142..6f05ec36667 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) {