I hear you. I have lived through that. When I worked at a few Microsoft partners back in the bad old days I even had stipulations in my contract that I wasn't allowed to contribute to free software projects without permission. Every time I asked for permission I was denied. When I was young I put up with it because progressing in these companies seemed to be important to me. Now I simply would not sign such a contract. I'm a contractor now and so I'm a lot more free than before, however in my last job I got explicit assurances up front that I was allowed to write my own code.
Luckily there are a lot of places around that will accommodate you these days. They may not be the highest paying jobs, but I'm willing to take a huge pay cut to ensure my freedom to code.