mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
(svn r20082) -Fix [FS#3899]: reading deleted memory when selecting a NewGRF in the content download window of which the data has not been acquired from the content server. The crash would occur after the content server's reply was processed and the ContentInfo object was replaced with another.
This commit is contained in:
parent
049c5536bc
commit
5003a7e311
@ -132,8 +132,16 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_INFO)
|
||||
if (StrEmpty(ci->name)) strecpy(ci->name, ici->name, lastof(ci->name));
|
||||
if (ici->IsSelected()) ci->state = ici->state;
|
||||
|
||||
delete ici;
|
||||
*iter = ci;
|
||||
/*
|
||||
* As ici might be selected by the content window we cannot delete that.
|
||||
* However, we want to keep most of the values of ci, except the values
|
||||
* we (just) already preserved. As there are already allocated blobs of
|
||||
* memory and more may be added, we cannot simply copy ci to ici as that
|
||||
* might cause a leak of memory. As such we need to swap the data and
|
||||
* then delete the memory we allocated here.
|
||||
*/
|
||||
Swap(*ici, *ci);
|
||||
delete ci;
|
||||
|
||||
this->OnReceiveContentInfo(ci);
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user