Is it a semi auto or a revolver?
Will be different as to specific tactics and when the firearm is dangerous and in what manner it is dangerous.
First control the barrel assuring the muzzle never is pointed toward any part of your body.
If a semi auto and controlling the barrel and slide the firearm can discharge once and then the firearm becomes a blunt object due to having a failure to feed. There will have to be a cycling of the slide and even a removal of the magazine, cycling of the slide, reinstalling the magazine, and then a cycling of the slide once again to make the firearm dischargeable. If a revolver with a external hammer in-order for the weapon to fire besides having a loaded cylinder bore, a couple of things have to happen. One the hammer must be retracted and the cylinder must turn. This happens as the trigger is pulled. So besides keeping the muzzle pointed away from your body parts holding the barrel in a manner that prevents the cylinder from turning the weapon will not fire. However, if there is a live cartridge in the aligned cylinder and barrel And the hammer is cocked the weapon will fire once and then the above becomes true again with the cylinder having to turn. To prevent the discharge of a revolver with a cocked hammer something like a finger, when grasping the revolver must be between the hammer and the firing pin. Will pinch and can be painful but will prevent the discharge as long as it prevents the hammer from striking the firing pin. If a revolver with an internal hammer preventing the cylinder from turning will prevent a discharge.
Either way you are in a very bad situation grappling vs a person with a firearm.