When I worked at reddit, we open sourced our code. It didn't gain us much. We got a few contributions, and we also got a few competitors. The biggest benefit was being able to show people the code when they suspected shenanigans.
At Netflix our ethos was "if it's involved in infrastructure, open source it, if it's related to movies, keep it closed." That actually worked pretty well. But the open source code was difficult to use unless you invested in the entire ecosystem. The main benefit was recruiting.
For my own company, I try to support open source by donating to the people who make it.