> I wonder how companies protect their source code from leaking
The prospect of being bankrupted by a civil suit or thrown in prison is enough to stop most people.
Yes, but... if you're good enough to be hired by these companies, leaking source code without being traced isn't going to be hard for you. I've thought about this before and I'm actually surprised it doesn't happen more often.
Not sure who wrote this but it seems fairly accurate to my memory of those days:
http://www.fortunecity.com/meltingpot/nebraska/1386/applehac...
The reality though is that such source code is hardly ever a requirement to understanding or reverse engineering the underlying algorithm, and is likely already obsolete by the time it becomes public.
There are companies already which specialize in DLP. Here is a PDF booklet by one of them: http://www.ironport.com/pdf/ironport_dlp_booklet.pdf