1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 00:42:45 +01:00

Codechange: Remove redundant NewsStringData data. (#12983)

Since SetDParamStr() always owns a copy of the string, there is no need to make another copy of it to keep it around while the news item exists.

This also fixes a leak in `CmdIndustrySetProduction` as the allocated data wasn't passed to AddIndustryNewsItem.
This commit is contained in:
Peter Nelson
2024-10-08 19:48:55 +01:00
committed by GitHub
parent d53b681cf7
commit 446db2c826
5 changed files with 14 additions and 23 deletions

View File

@@ -2207,10 +2207,8 @@ CommandCost CmdIndustrySetProduction(DoCommandFlag flags, IndustryID ind_id, uin
}
/* Set parameters of news string */
NewsAllocatedData *data = nullptr;
if (str == STR_NEWS_CUSTOM_ITEM) {
NewsStringData *news = new NewsStringData(custom_news);
SetDParamStr(0, news->string);
SetDParamStr(0, custom_news);
} else if (str > STR_LAST_STRINGID) {
SetDParam(0, STR_TOWN_NAME);
SetDParam(1, ind->town->index);
@@ -2218,7 +2216,7 @@ CommandCost CmdIndustrySetProduction(DoCommandFlag flags, IndustryID ind_id, uin
} else {
SetDParam(0, ind->index);
}
AddIndustryNewsItem(str, nt, ind->index, data);
AddIndustryNewsItem(str, nt, ind->index);
}
}