mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 22:37:50 +00:00
Bug 1124973 (part 3) - Use PL_DHashTableSearch() in nsHostResolver.cpp. r=froydnj,sworkman.
Currently nsHostResolver.cpp uses PL_DHashTableLookup() and fails to use PL_DHASH_ENTRY_IS_{FREE,BUSY} on the result the way it should. However, I think it gets away with this because it always does this on the result: if (!he || !he->rec) { /* do stuff with |he->rec| */ } The |!he| test is useless and always fails, but the |!he->rec| does the right thing because (a) entry storage is always zeroed when the table is created, (b) HostDB_ClearEntry() zeroes the |rec| field (via NS_RELEASE). So unused entries always have a null |rec| field. Furthermore, |he->rec| is never zero in a used entry because HostDB_InitEntry always assigns it with a nsHostRecord assigned with infallible new in nsHostRecord::Create (and there are existing assertions to this effect). All this means that when this patch switches PL_DHashTableLookup to PL_DHashTableSearch it can drop the |!he->rec| test and just do this: if (!he) { /* do stuff with |he->rec| */ } Finally, there's a comment about HostDB_InitEntry failing which is bogus because HostDB_InitEntry cannot fail. This patch fixes that too. --HG-- extra : rebase_source : ded6f8ff404cb160d89bbe7deeb3b863249bdb94
This commit is contained in:
parent
3163cfc2c1
commit
c801affedb
@ -758,8 +758,8 @@ nsHostResolver::ResolveHost(const char *host,
|
||||
nsHostDBEnt *he = static_cast<nsHostDBEnt *>
|
||||
(PL_DHashTableAdd(&mDB, &key));
|
||||
|
||||
// if the record is null, then HostDB_InitEntry failed.
|
||||
if (!he || !he->rec) {
|
||||
// if the record is null, the hash table OOM'd.
|
||||
if (!he) {
|
||||
LOG((" Out of memory: no cache entry for [%s].\n", host));
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
@ -834,7 +834,6 @@ nsHostResolver::ResolveHost(const char *host,
|
||||
(unspecHe && unspecHe->rec),
|
||||
"Valid host entries should contain a record");
|
||||
if (unspecHe &&
|
||||
unspecHe->rec &&
|
||||
unspecHe->rec->HasUsableResult(TimeStamp::NowLoRes(), flags)) {
|
||||
|
||||
MOZ_ASSERT(unspecHe->rec->addr_info || unspecHe->rec->negative,
|
||||
@ -956,8 +955,8 @@ nsHostResolver::DetachCallback(const char *host,
|
||||
|
||||
nsHostKey key = { host, flags, af };
|
||||
nsHostDBEnt *he = static_cast<nsHostDBEnt *>
|
||||
(PL_DHashTableLookup(&mDB, &key));
|
||||
if (he && he->rec) {
|
||||
(PL_DHashTableSearch(&mDB, &key));
|
||||
if (he) {
|
||||
// walk list looking for |callback|... we cannot assume
|
||||
// that it will be there!
|
||||
PRCList *node = he->rec->callbacks.next;
|
||||
@ -1304,8 +1303,8 @@ nsHostResolver::CancelAsyncRequest(const char *host,
|
||||
// Lookup the host record associated with host, flags & address family
|
||||
nsHostKey key = { host, flags, af };
|
||||
nsHostDBEnt *he = static_cast<nsHostDBEnt *>
|
||||
(PL_DHashTableLookup(&mDB, &key));
|
||||
if (he && he->rec) {
|
||||
(PL_DHashTableSearch(&mDB, &key));
|
||||
if (he) {
|
||||
nsHostRecord* recPtr = nullptr;
|
||||
PRCList *node = he->rec->callbacks.next;
|
||||
// Remove the first nsDNSAsyncRequest callback which matches the
|
||||
|
Loading…
x
Reference in New Issue
Block a user