If possible, take a can of compressed air and blow it into the headphone jack.
Insert the headphones completely. Remove them. Do this for seven or eight times.
Afaik that's not a software glitch. It rather is a hardware bug. The sensor in your jack thinks the headphones are still attached. I'm in doubt that restoring will help in your case.