NetworkCookieJar: don't leak a new cookie if it has expired
This commit is contained in:
@@ -91,7 +91,9 @@ BNetworkCookieJar::AddCookie(const BNetworkCookie& cookie)
|
|||||||
bool
|
bool
|
||||||
BNetworkCookieJar::AddCookie(BNetworkCookie* cookie)
|
BNetworkCookieJar::AddCookie(BNetworkCookie* cookie)
|
||||||
{
|
{
|
||||||
if (cookie != NULL) {
|
if (cookie == NULL || cookie->ShouldDeleteNow())
|
||||||
|
return false;
|
||||||
|
|
||||||
HashString key(cookie->Domain());
|
HashString key(cookie->Domain());
|
||||||
|
|
||||||
if (!fCookieHashMap->fHashMap.ContainsKey(key))
|
if (!fCookieHashMap->fHashMap.ContainsKey(key))
|
||||||
@@ -109,11 +111,7 @@ BNetworkCookieJar::AddCookie(BNetworkCookie* cookie)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discard the cookie if it's to be deleted
|
|
||||||
if (!cookie->ShouldDeleteNow())
|
|
||||||
list->AddItem(cookie);
|
list->AddItem(cookie);
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +142,7 @@ BNetworkCookieJar::DeleteOutdatedCookies()
|
|||||||
int32 deleteCount = 0;
|
int32 deleteCount = 0;
|
||||||
BNetworkCookie* cookiePtr;
|
BNetworkCookie* cookiePtr;
|
||||||
|
|
||||||
for (Iterator it(GetIterator()); (cookiePtr = it.Next()); ) {
|
for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) {
|
||||||
if (cookiePtr->ShouldDeleteNow()) {
|
if (cookiePtr->ShouldDeleteNow()) {
|
||||||
delete it.Remove();
|
delete it.Remove();
|
||||||
deleteCount++;
|
deleteCount++;
|
||||||
@@ -161,7 +159,7 @@ BNetworkCookieJar::PurgeForExit()
|
|||||||
int32 deleteCount = 0;
|
int32 deleteCount = 0;
|
||||||
BNetworkCookie* cookiePtr;
|
BNetworkCookie* cookiePtr;
|
||||||
|
|
||||||
for (Iterator it(GetIterator()); (cookiePtr = it.Next()); ) {
|
for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) {
|
||||||
if (cookiePtr->ShouldDeleteAtExit()) {
|
if (cookiePtr->ShouldDeleteAtExit()) {
|
||||||
delete it.Remove();
|
delete it.Remove();
|
||||||
deleteCount++;
|
deleteCount++;
|
||||||
@@ -183,7 +181,7 @@ BNetworkCookieJar::Archive(BMessage* into, bool deep) const
|
|||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
BNetworkCookie* cookiePtr;
|
BNetworkCookie* cookiePtr;
|
||||||
|
|
||||||
for (Iterator it(GetIterator()); (cookiePtr = it.Next()); ) {
|
for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) {
|
||||||
BMessage subArchive;
|
BMessage subArchive;
|
||||||
|
|
||||||
error = cookiePtr->Archive(&subArchive, deep);
|
error = cookiePtr->Archive(&subArchive, deep);
|
||||||
@@ -357,7 +355,7 @@ BNetworkCookieJar::_DoFlatten() const
|
|||||||
fFlattened.Truncate(0);
|
fFlattened.Truncate(0);
|
||||||
|
|
||||||
BNetworkCookie* cookiePtr;
|
BNetworkCookie* cookiePtr;
|
||||||
for (Iterator it(GetIterator()); (cookiePtr = it.Next()); ) {
|
for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) {
|
||||||
fFlattened << cookiePtr->Domain() << '\t' << "TRUE" << '\t'
|
fFlattened << cookiePtr->Domain() << '\t' << "TRUE" << '\t'
|
||||||
<< cookiePtr->Path() << '\t'
|
<< cookiePtr->Path() << '\t'
|
||||||
<< (cookiePtr->Secure()?"TRUE":"FALSE") << '\t'
|
<< (cookiePtr->Secure()?"TRUE":"FALSE") << '\t'
|
||||||
|
|||||||
Reference in New Issue
Block a user