Mercurial > hg > openttd
changeset 15439:52d825a14c24 draft
(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.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 05 Jul 2010 21:07:31 +0000 |
parents | 36d0467df244 |
children | ede5b084cd0a |
files | src/network/network_content.cpp |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -132,8 +132,16 @@ 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;