diff --git a/netwerk/cookie/nsCookie.cpp b/netwerk/cookie/nsCookie.cpp index 4cefa2131294..e9aa9835b3cd 100644 --- a/netwerk/cookie/nsCookie.cpp +++ b/netwerk/cookie/nsCookie.cpp @@ -75,13 +75,12 @@ int64_t nsCookie::GenerateUniqueCreationTime(int64_t aCreationTime) { return ++gLastCreationTime; } -nsCookie* nsCookie::Create(const nsACString& aName, const nsACString& aValue, - const nsACString& aHost, const nsACString& aPath, - int64_t aExpiry, int64_t aLastAccessed, - int64_t aCreationTime, bool aIsSession, - bool aIsSecure, bool aIsHttpOnly, - const OriginAttributes& aOriginAttributes, - int32_t aSameSite) { +// static +already_AddRefed nsCookie::Create( + const nsACString& aName, const nsACString& aValue, const nsACString& aHost, + const nsACString& aPath, int64_t aExpiry, int64_t aLastAccessed, + int64_t aCreationTime, bool aIsSession, bool aIsSecure, bool aIsHttpOnly, + const OriginAttributes& aOriginAttributes, int32_t aSameSite) { // Ensure mValue contains a valid UTF-8 sequence. Otherwise XPConnect will // truncate the string after the first invalid octet. nsAutoCString aUTF8Value; @@ -111,9 +110,11 @@ nsCookie* nsCookie::Create(const nsACString& aName, const nsACString& aValue, } // construct the cookie. placement new, oh yeah! - return new (place) nsCookie( + RefPtr cookie = new (place) nsCookie( name, value, host, path, end, aExpiry, aLastAccessed, aCreationTime, aIsSession, aIsSecure, aIsHttpOnly, aOriginAttributes, aSameSite); + + return cookie.forget(); } size_t nsCookie::SizeOfIncludingThis( diff --git a/netwerk/cookie/nsCookie.h b/netwerk/cookie/nsCookie.h index 8dc6089f5cb3..e86a88719486 100644 --- a/netwerk/cookie/nsCookie.h +++ b/netwerk/cookie/nsCookie.h @@ -59,15 +59,13 @@ class nsCookie final : public nsICookie2 { // in nsCookie.cpp. static int64_t GenerateUniqueCreationTime(int64_t aCreationTime); - // public helper to create an nsCookie object. use |operator delete| - // to destroy an object created by this method. - static nsCookie* Create(const nsACString& aName, const nsACString& aValue, - const nsACString& aHost, const nsACString& aPath, - int64_t aExpiry, int64_t aLastAccessed, - int64_t aCreationTime, bool aIsSession, - bool aIsSecure, bool aIsHttpOnly, - const OriginAttributes& aOriginAttributes, - int32_t aSameSite); + // public helper to create an nsCookie object. + static already_AddRefed Create( + const nsACString& aName, const nsACString& aValue, + const nsACString& aHost, const nsACString& aPath, int64_t aExpiry, + int64_t aLastAccessed, int64_t aCreationTime, bool aIsSession, + bool aIsSecure, bool aIsHttpOnly, + const OriginAttributes& aOriginAttributes, int32_t aSameSite); size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;