Bug 1341238 - Don't hang on to pointer from temporary NS_LossyConvertUTF16toASCII. r=padenot
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -170,21 +170,20 @@ void PrefChanged(const char* aPref, void
cubeb_set_log_callback(CUBEB_LOG_DISABLED, nullptr);
cubebLog->SetLevel(LogLevel::Disabled);
}
} else if (strcmp(aPref, PREF_CUBEB_BACKEND) == 0) {
nsAdoptingString value = Preferences::GetString(aPref);
if (value.IsEmpty()) {
sCubebBackendName = nullptr;
} else {
- /* cubeb expects a c-string. */
- const char* ascii = NS_LossyConvertUTF16toASCII(value).get();
- sCubebBackendName = new char[value.Length() + 1];
- PodCopy(sCubebBackendName.get(), ascii, value.Length());
- sCubebBackendName[value.Length()] = 0;
+ NS_LossyConvertUTF16toASCII ascii(value);
+ sCubebBackendName = new char[ascii.Length() + 1];
+ PodCopy(sCubebBackendName.get(), ascii.get(), ascii.Length());
+ sCubebBackendName[ascii.Length()] = 0;
}
}
}
bool GetFirstStream()
{
static bool sFirstStream = true;
@@ -313,21 +312,20 @@ void InitBrandName()
getter_AddRefs(brandBundle));
if (NS_SUCCEEDED(rv)) {
rv = brandBundle->GetStringFromName(u"brandShortName",
getter_Copies(brandName));
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "Could not get the program name for a cubeb stream.");
}
}
- /* cubeb expects a c-string. */
- const char* ascii = NS_LossyConvertUTF16toASCII(brandName).get();
- sBrandName = new char[brandName.Length() + 1];
- PodCopy(sBrandName.get(), ascii, brandName.Length());
- sBrandName[brandName.Length()] = 0;
+ NS_LossyConvertUTF16toASCII ascii(brandName);
+ sBrandName = new char[ascii.Length() + 1];
+ PodCopy(sBrandName.get(), ascii.get(), ascii.Length());
+ sBrandName[ascii.Length()] = 0;
}
cubeb* GetCubebContextUnlocked()
{
sMutex.AssertCurrentThreadOwns();
if (sCubebState != CubebState::Uninitialized) {
// If we have already passed the initialization point (below), just return
// the current context, which may be null (e.g., after error or shutdown.)