From 84038e63d4c3ba4acaeeb29ff1c639d22d7f07cb Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Sat, 20 Feb 2016 11:06:25 +0800 Subject: [PATCH] Bug 1248851 part 1 - Explicitly mark some release() calls result-unused. r=Waldo MozReview-Commit-ID: Cgubemm1Et3 --- dom/network/TCPSocketChild.cpp | 4 +++- dom/workers/FileReaderSync.cpp | 5 ++++- js/src/builtin/TestingFunctions.cpp | 3 ++- js/src/jsstr.cpp | 7 ++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/dom/network/TCPSocketChild.cpp b/dom/network/TCPSocketChild.cpp index e93b448db26..2de5ecfbe84 100644 --- a/dom/network/TCPSocketChild.cpp +++ b/dom/network/TCPSocketChild.cpp @@ -34,7 +34,9 @@ DeserializeArrayBuffer(JSContext* cx, JSObject* obj = JS_NewArrayBufferWithContents(cx, aBuffer.Length(), data.get()); if (!obj) return false; - data.release(); + // If JS_NewArrayBufferWithContents returns non-null, the ownership of + // the data is transfered to obj, so we release the ownership here. + mozilla::Unused << data.release(); aVal.setObject(*obj); return true; diff --git a/dom/workers/FileReaderSync.cpp b/dom/workers/FileReaderSync.cpp index 5bd8e0122e4..4620544e483 100644 --- a/dom/workers/FileReaderSync.cpp +++ b/dom/workers/FileReaderSync.cpp @@ -7,6 +7,7 @@ #include "FileReaderSync.h" #include "jsfriendapi.h" +#include "mozilla/unused.h" #include "mozilla/Base64.h" #include "mozilla/dom/EncodingUtils.h" #include "mozilla/dom/File.h" @@ -85,7 +86,9 @@ FileReaderSync::ReadAsArrayBuffer(JSContext* aCx, aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } - bufferData.release(); + // arrayBuffer takes the ownership when it is not null. Otherwise we + // need to release it explicitly. + mozilla::Unused << bufferData.release(); aRetval.set(arrayBuffer); } diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 71b31b11c0e..59e702d3ba7 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -7,6 +7,7 @@ #include "builtin/TestingFunctions.h" #include "mozilla/Move.h" +#include "mozilla/unused.h" #include @@ -2612,7 +2613,7 @@ FindPath(JSContext* cx, unsigned argc, Value* vp) RootedString edgeStr(cx, NewString(cx, edgeName.get(), js_strlen(edgeName.get()))); if (!edgeStr) return false; - edgeName.release(); // edgeStr acquired ownership + mozilla::Unused << edgeName.release(); // edgeStr acquired ownership if (!JS_DefineProperty(cx, obj, "edge", edgeStr, JSPROP_ENUMERATE, nullptr, nullptr)) return false; diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index 2f27187670e..f100561851b 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -13,6 +13,7 @@ #include "mozilla/PodOperations.h" #include "mozilla/Range.h" #include "mozilla/TypeTraits.h" +#include "mozilla/unused.h" #include #include @@ -645,7 +646,7 @@ ToLowerCase(JSContext* cx, JSLinearString* str) if (!res) return nullptr; - newChars.release(); + mozilla::Unused << newChars.release(); return res; } @@ -788,13 +789,13 @@ ToUpperCase(JSContext* cx, JSLinearString* str) if (!res) return nullptr; - newChars.ref().release(); + mozilla::Unused << newChars.ref().release(); } else { res = NewStringDontDeflate(cx, newChars.ref().get(), length); if (!res) return nullptr; - newChars.ref().release(); + mozilla::Unused << newChars.ref().release(); } return res;