Rethinking Safety in LLM Fine-tuning: An Optimization Perspective