If you have done a factory restore and the problem remains, what makes you think this is a malware problem?
There is every chance this is an hardware problem. Maybe your cpu heatsink needs reseating? Maybe your graphics card is getting too hot?
Considering it does it whilst you are gaming, these are the things I would be looking at, as well as the memory.