Is safe sex, I mean masturbation okay?

Absolutely. This has been discussed before - I recommend you read up on it:

and