Skip to content

Commit b769db9

Browse files
committed
Bug 1347657 - Use array entry as value instead of reference to avoid 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 --HG-- extra : rebase_source : 4bf61a8a6f6bc57523dfbb7e5b0b40b7ce77a57a
1 parent cd45a3e commit b769db9

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ nsUrlClassifierStreamUpdater::FetchNextRequest()
375375
return NS_OK;
376376
}
377377

378-
PendingRequest &request = mPendingRequests[0];
378+
PendingRequest request = mPendingRequests[0];
379+
mPendingRequests.RemoveElementAt(0);
379380
LOG(("Stream updater: fetching next request: %s, %s",
380381
request.mTables.get(), request.mUrl.get()));
381382
bool dummy;
@@ -388,11 +389,6 @@ nsUrlClassifierStreamUpdater::FetchNextRequest()
388389
request.mUpdateErrorCallback,
389390
request.mDownloadErrorCallback,
390391
&dummy);
391-
request.mSuccessCallback = nullptr;
392-
request.mUpdateErrorCallback = nullptr;
393-
request.mDownloadErrorCallback = nullptr;
394-
mPendingRequests.RemoveElementAt(0);
395-
396392
return NS_OK;
397393
}
398394

0 commit comments

Comments
 (0)