Opened 8 years ago

Last modified 6 years ago

#4257 closed defect

Freeze cached session objects — at Initial Version

Reported by: elexis Owned by:
Priority: Must Have Milestone: Alpha 23
Component: UI & Simulation Keywords:
Cc: Patch:

Description

The functions GetSimState, GetEntityState, GetExtendedEntityState, GetTemplateData, GetTemplateDataWithoutLocalization, GetTechnologyData cache their results in global variables and return these objects each.

However, returning an object means that the reference is returned, not a copy. This isn't an issue if that object was newly created (or cloned). But if the function returns an object which is accessible outside of the scope of the function (f.e. a global cache variable), modifying the returned object modifies the cache, which is not intentional and adulterates the original data.

This is often not considered and has caused a number of bugs already, f.e. r18788 r17324 r17441 r17712 r17715.

The mentioned functions should use Object.freeze to ensure that the returned object can't be modified.

There are likely many other places in gui/ where global variables are used to cache things, that should be frozen.

Change History (0)

Note: See TracTickets for help on using tickets.