Welcome to HCM.
The infection that you have is called Balanoposthitis
. You have not mentioned your age.
This needs to be treated with antibiotics. Consult an urologist
and he will treat you after examination. Regularly clean your penis and retract the foreskin and clean the insides also with soap and water. At present it may not be possible to retract the foreskin but after treatment make it a regular habit to clean the area as mentioned above.Masturbation
does not cause balanopostitis, but if you leave the semen on the penis for long, it will lead to infection. The basic requirement is to maitain basic hygiene and keep the area very clean by frequent washing.
Rule out diabetes
Wish you all the best.