From 326ce405209d3910d014d7ed4e950f3149ee839e Mon Sep 17 00:00:00 2001 From: usa Date: Wed, 6 Feb 2013 05:14:53 +0000 Subject: merge revision(s) 37174: [Backport #7754] * file.c (realpath_rec): prevent link from GC while link_names refers the content. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@39092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'file.c') diff --git a/file.c b/file.c index 50fa5c7f2c..fd64116d24 100644 --- a/file.c +++ b/file.c @@ -3378,6 +3378,7 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE l #ifdef HAVE_READLINK if (S_ISLNK(sbuf.st_mode)) { VALUE link; + volatile VALUE link_orig = Qnil; const char *link_prefix, *link_names; long link_prefixlen; rb_hash_aset(loopcheck, testpath, ID2SYM(resolving)); @@ -3387,6 +3388,7 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE l link_prefixlen = link_names - link_prefix; if (link_prefixlen > 0) { rb_encoding *enc, *linkenc = rb_enc_get(link); + link_orig = link; link = rb_str_subseq(link, 0, link_prefixlen); enc = rb_enc_check(*resolvedp, link); if (enc != linkenc) link = rb_str_conv_enc(link, linkenc, enc); @@ -3394,6 +3396,7 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE l *prefixlenp = link_prefixlen; } realpath_rec(prefixlenp, resolvedp, link_names, loopcheck, strict, *unresolved_firstsep == '\0'); + RB_GC_GUARD(link_orig); rb_hash_aset(loopcheck, testpath, rb_str_dup_frozen(*resolvedp)); } else -- cgit v1.2.3