Sure, that just happens to be a concern that's bordering on silly. Any company that you interact with could turn malicious and do nasty stuff. As has been pointed out already, with git there's zero danger of you losing your code so long as you keep a local repo up to date.
In the case of Sourceforge, projects like GIMP have ignored years of warning signs. IIRC it was 2012 or 2013 when SF started inserting adware into installers.
With a planned shutdown like Google Code, you're given numerous warnings to migrate to a new host.
I only gave you some of the reasons, there are many more.
As an individual or organisation, you may decide to either do adverts, to help pay for things or be really nice, and have no adverts, or something, in between.
But if you use external (free) hosts, you usually CAN'T make them ad free, and if there are adverts, you WON'T get any of the money/benefits from them (usually).
You might want to have lots of statistics, to tell you about who, when, from where, how many times, your stuff is accessed/downloaded. Your own services, will allow you to fully collect that information, to your hearts, desire. Which can help you improve things in the future.
Free/external hosts, may not provide that information, and/or it was not the specific information that you were looking for.
Probably by paying for better services (hosts), you can get some/all of the above, so there are counter arguments you can make.
There can also be limitations, which can end up being a real pain.
Some people like desktop PCs, others really like laptops.
I don't think there are "right" and "wrong" answers here. Both using free/paid external hosts and/or running your own server(s). Are probably both viable options, if someone wants to go down that path.
A person can learn a lot of useful stuff, if they run their own server(s). This can significantly help their careers and/or business activities and/or leisure pursuits. Assuming that is their direction in life.
If you otherwise (job/business/hobby), have little or no involvement with computers/IT, then maybe free/paid external hosts makes a lot more sense.
There is a lot of work involved in setting up server(s), and costs involved. So there are many benefits, for the free/paid services. Even massive companies, sometimes almost exclusively use external (web etc) services, such as cloud etc. (I have been led to believe).