From 26e4e8d2ad6cfba26004e83202a9d6fea6b9c18f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 9 Jun 2021 17:04:49 +0300 Subject: [PATCH 64/64] savegame3.c: Fix loading multiresearch values - Fixed memory leak - Don't free() memory that should not be freed - Assign bulbs to correct techs when ruleset has changed See osdn #42499 Signed-off-by: Marko Lindqvist --- server/savegame/savegame3.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 3079a79f41..bf6ea140d0 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -7034,7 +7034,6 @@ static void sg_load_researches(struct loaddata *loading) const char *str; int i, j; int *vlist_research; - size_t count_res; vlist_research = NULL; /* Check status and return if not OK (sg_success != TRUE). */ @@ -7106,14 +7105,19 @@ static void sg_load_researches(struct loaddata *loading) } if (game.server.multiresearch) { - vlist_research = fc_calloc(game.control.num_tech_types, sizeof(int)); + size_t count_res; + int tn; + vlist_research = secfile_lookup_int_vec(loading->file, &count_res, "research.r%d.vbs", i); - advance_index_iterate(A_FIRST, o) { - presearch->inventions[o].bulbs_researched_saved = vlist_research[o]; - } advance_index_iterate_end; - if (vlist_research) { - free(vlist_research); + + for (tn = 0; tn < count_res; tn++) { + struct advance *padvance = advance_by_rule_name(loading->technology.order[tn]); + + if (padvance != NULL) { + presearch->inventions[advance_index(padvance)].bulbs_researched_saved + = vlist_research[tn]; + } } } } -- 2.30.2