Bug 1187410 - Use GetNameShared() in XPCNativeInterface::NewInstance() to avoid a leak. r=mrbkap
authorAndrew McCreight <continuation@gmail.com>
Sun, 26 Jul 2015 14:26:23 -0700
changeset 254619 23952da58da6570043876a18f2592039368245fd
parent 254618 6150fa09d51f36af7afa9ccf2c0ed4c183daf95d
child 254620 2d544a479afa6a2c398cc40eb0511af8db85d592
push id29108
push userryanvm@gmail.com
push dateMon, 27 Jul 2015 14:12:01 +0000
treeherdermozilla-central@27ae736ef960 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1187410
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1187410 - Use GetNameShared() in XPCNativeInterface::NewInstance() to avoid a leak. r=mrbkap GetName() returns a new string, but that string is never freed. This patch avoids the leak by not copying the string. This is okay because the scope of intfNameChars is within the scope of aInfo.
js/xpconnect/src/XPCWrappedNativeInfo.cpp
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -234,18 +234,18 @@ XPCNativeInterface::NewInstance(nsIInter
         return nullptr;
 
     bool mainProcessScriptableOnly;
     if (NS_FAILED(aInfo->IsMainProcessScriptableOnly(&mainProcessScriptableOnly)))
         return nullptr;
     if (mainProcessScriptableOnly && !XRE_IsParentProcess()) {
         nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
         if (console) {
-            char* intfNameChars;
-            aInfo->GetName(&intfNameChars);
+            const char* intfNameChars;
+            aInfo->GetNameShared(&intfNameChars);
             nsPrintfCString errorMsg("Use of %s in content process is deprecated.", intfNameChars);
 
             nsAutoString filename;
             uint32_t lineno = 0;
             nsJSUtils::GetCallingLocation(cx, filename, &lineno);
             nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
             error->Init(NS_ConvertUTF8toUTF16(errorMsg),
                         filename, EmptyString(),