Skip to content

Commit cab5a6e

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 UltraBlame original commit: 2d4a86ef46e9b45b516165ff624068fbcc4493ce
1 parent f2f685b commit cab5a6e

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,14 +2503,20 @@ NS_OK
25032503
;
25042504
}
25052505
PendingRequest
2506-
&
25072506
request
25082507
=
25092508
mPendingRequests
25102509
[
25112510
0
25122511
]
25132512
;
2513+
mPendingRequests
2514+
.
2515+
RemoveElementAt
2516+
(
2517+
0
2518+
)
2519+
;
25142520
LOG
25152521
(
25162522
(
@@ -2574,31 +2580,6 @@ mDownloadErrorCallback
25742580
dummy
25752581
)
25762582
;
2577-
request
2578-
.
2579-
mSuccessCallback
2580-
=
2581-
nullptr
2582-
;
2583-
request
2584-
.
2585-
mUpdateErrorCallback
2586-
=
2587-
nullptr
2588-
;
2589-
request
2590-
.
2591-
mDownloadErrorCallback
2592-
=
2593-
nullptr
2594-
;
2595-
mPendingRequests
2596-
.
2597-
RemoveElementAt
2598-
(
2599-
0
2600-
)
2601-
;
26022583
return
26032584
NS_OK
26042585
;

0 commit comments

Comments
 (0)