Skip to content

Commit

Permalink
Bug 1347657 - Use array entry as value instead of reference to avoid …
Browse files Browse the repository at this point in the history
…being invalidated by realloc. r=francois

nsTArray::AppendElement may cause memory reallocation if out of capacity.
In nsUrlClassifierStreamUpdater::FetchNextRequest(), we take the reference of
the first element of mPendingRequests and pass its member as reference to
DownloadUpdate(), where mPendingRequests.AppendElement will be called.
If the AppendElement in DownloadUpdate() causes realloc, the reference
becomes dangling.

The most efficient fix is to "move" the reference's (i.e. request)
member variables to DownloadUpdate() but I think in this case we can just
take the value from the array and pass it around with no given that the
array element contains simply a couple of strings and pointers.

MozReview-Commit-ID: KEZ5d3l3HoI
  • Loading branch information
elefant committed Mar 16, 2017
1 parent 7b61850 commit 52abba2
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ nsUrlClassifierStreamUpdater::FetchNextRequest()
return NS_OK;
}

PendingRequest &request = mPendingRequests[0];
PendingRequest request = mPendingRequests[0];
mPendingRequests.RemoveElementAt(0);
LOG(("Stream updater: fetching next request: %s, %s",
request.mTables.get(), request.mUrl.get()));
bool dummy;
Expand All @@ -388,11 +389,6 @@ nsUrlClassifierStreamUpdater::FetchNextRequest()
request.mUpdateErrorCallback,
request.mDownloadErrorCallback,
&dummy);
request.mSuccessCallback = nullptr;
request.mUpdateErrorCallback = nullptr;
request.mDownloadErrorCallback = nullptr;
mPendingRequests.RemoveElementAt(0);

return NS_OK;
}

Expand Down

0 comments on commit 52abba2

Please sign in to comment.