I think I would have done it a bit differently, as there are some issues with this. This way, what happens if the unit dies while upgrading? Does the item get dropped in the center of the map? This will happen a certain point after death as the unit will be removed from the game's memory, although not likely 1.2 seconds after. What happens if multiple buildings upgrade within a 1.2 second timeframe? The loop variables are global, so it would increase the number to 2 and then give 2 items to 1 of them and 0 items to the other, since you have a wait function.
The "best practice" way to do this is to use a hashtable. The simplest way to do it is using a custom value.
If you were to go with a custom value, it's quite easy. When the unit starts an upgrade, remove the potion and assign a custom value to it that means that a mana potion was removed from it, like 42. That's it, 1 action, no variables.
Then you make a second trigger with 3 events. One is that the structure cancels the upgrade, another is that the structure dies, and the third is that it finishes the upgrade. Then, you add a condition checking if the custom value of the unit is 42 (in this example, again, any number works), and if it is, you give the unit a mana potion and set the custom value to 0.
In this case, I am fairly certain that the dead building will have the item dropped on it, as the trigger doesn't lose the location of the unit when there is no time gap such as wait in the trigger. This also works smoothly with any level of upgrade time on the building, in case you wanna use this on buildings with an upgrade time that's above 1 second.
With a hashtable, what you'd want to do is assign an item type to the unit handle at a given index and then go with that. Wouldn't interfere with Unit Indexing systems, but if you don't use that, then just use the custom value thing instead, it's simpler.
And for the Big bad voodoo I just used a dummy unit, I guess it doesn't like it if u have a building casting it.
Not a bad solution, but make sure of the following:
The dummy unit should be able to be at the center of the structure, likely flying.
The structure should have an effect attached to it, unless you manage to get the spell effect from the dummy down to the building.
You need to ensure that the building kills the dummy unit if it dies while the cast is up, that's the whole point of Big Bad Voodoo after all.