Bug 1145812 - Fix assertion with dom.url.encode_decode_hash pref set to true. r=mcmanus, a=sledru
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 23 Mar 2015 23:28:50 +0200
changeset 260226 5f0e381a7afd
parent 260225 d55fdde73ac8
child 260227 0b3c5b65610e
push id723
push userryanvm@gmail.com
push date2015-04-22 14:15 +0000
treeherdermozilla-release@22f8fa3a9273 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, sledru
bugs1145812
milestone38.0
Bug 1145812 - Fix assertion with dom.url.encode_decode_hash pref set to true. r=mcmanus, a=sledru
netwerk/base/nsStandardURL.cpp
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -2502,19 +2502,21 @@ nsStandardURL::SetRef(const nsACString &
     
     if (mRef.mLen < 0) {
         mSpec.Append('#');
         ++mPath.mLen;  // Include the # in the path.
         mRef.mPos = mSpec.Length();
         mRef.mLen = 0;
     }
 
+    // If precent encoding is necessary, `ref` will point to `buf`'s content.
+    // `buf` needs to outlive any use of the `ref` pointer.
+    nsAutoCString buf;
     if (nsContentUtils::EncodeDecodeURLHash()) {
         // encode ref if necessary
-        nsAutoCString buf;
         bool encoded;
         GET_SEGMENT_ENCODER(encoder);
         encoder.EncodeSegmentCount(ref, URLSegment(0, refLen), esc_Ref,
                                    buf, encoded);
         if (encoded) {
             ref = buf.get();
             refLen = buf.Length();
         }