| 1138 | |
| 1139 | |
| 1140 | void Var::FreeAndRestoreFunctionVars(UserFunc &aFunc, VarBkp *&aVarBackup, int &aVarBackupCount) |
| 1141 | { |
| 1142 | int i; |
| 1143 | for (i = 0; i < aFunc.mVars.mCount; ++i) |
| 1144 | aFunc.mVars.mItem[i]->Free(VAR_ALWAYS_FREE, true); // Pass "true" to exclude aliases, since their targets should not be freed (they don't belong to this function). Also resets the "uninitialized" attribute. |
| 1145 | |
| 1146 | // The freeing (above) MUST be done prior to the restore-from-backup below (otherwise there would be |
| 1147 | // a memory leak). Static variables are never backed up and thus do not exist in the aVarBackup array. |
| 1148 | // This is because by definition, the contents of statics are not freed or altered by the calling procedure |
| 1149 | // (regardless how recursive or multi-threaded the function is). |
| 1150 | if (aVarBackup) // This is the indicator that a backup was made; thus a restore is also needed. |
| 1151 | { |
| 1152 | for (i = 0; i < aVarBackupCount; ++i) // Static variables were never backed up so they won't be in this array. See comments above. |
| 1153 | { |
| 1154 | VarBkp &bkp = aVarBackup[i]; |
| 1155 | bkp.mVar->Restore(bkp); |
| 1156 | } |
| 1157 | free(aVarBackup); |
| 1158 | aVarBackup = NULL; // Some callers want this reset; it's an indicator of whether the next function call in this expression (if any) will have a backup. |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | |