IANAL but an employee generally does not have to just contribute work related code. The company has to OK it either for specific contributions or as a blanket policy, but it's opt in.
Then there is a secondary question on whether you contribute the code under a specific license (say Apache 2.0 GPL, etc.) or whether you assign the copyright.
In the former case the code can only be used in accordance with that specific license, in the latter case the code can be re-licensed by the copyright holder.
In either case the company could claim that the employee did not have the right to contribute the code, but (AFAIK) that is independent of a copyright grant vs license grant.