Depends on at what point the machine froze up.
Say you hit the spin button (costing you $2), the reels spun around and produced no winnings, then froze when you tried to spin again, there would be no reason to credit you back your $2 since. You were able to complete the spin.
Likewise, if in the same scenario, $2 spin, say you got bars across for $5, then it froze when you tried to spin again, you should have seen the $5 added to your credits. But again there would be no reason to credit your $2 back. You were able to complete the spin.
Now, if you hit the spin button, no spin occurred, and the credit meter showed "Played 2 coins", in a reputable place the tech checks this out, calls a supervisor over who can make the call, and hands you $2 in coin or bills (but it might take a while for all that to be done). Depends on the level of employee whether the first person on the scene can make all that happen quickly.
I believe as Cowboy said that a slot attendant would not be able to adjust credits on the machine itself.
You were right to get the heck away from that machine. They should have put it out of commission until it could be competently repaired.
You might have called over a supervisor to review it and perhaps get your $2 back.
The "malfunction voids all pays" is really to prevent paying out in the case of player trickery, alterations of machines, etc. that used to be fairly easy to do years ago. Again, reputable places would not quibble over $2 and would pay you back what you had put in if the play/spin did not occur.