It's not as simple as people are making it out to be.
They would have a hard time patenting your code/ algorithm (even though technically these are not patentable, in fact, abstract methods are patented all the time through the device of using a certain phraseology which is little more than a canned incantation involving the words "in one embodiment...")
What they could and will do, which is just as destructive and limiting to you and your future freedoms, is patent every *single* obvious *continuation* of the stream of thought or idea you were developing.
So on day 1 you release your code and on day 2 they are busy patenting the most obvious applications of your code as a process patent and every single natural extension of your code - what would have been version 1.2 to you. So you still have your code, but it's been relegated to a progress-ghetto that it can't get out of.
If you think about it, this is all they do already. They don't own the basis of any technology per se (although it took numerous court decisions and hundreds of millions of tax payer dollars to tell them this) . What they do lay claim to and what American courts uphold on a regular basis is just the further extension or natural elaboration or application of other people's ideas.
There is nothing stopping them from including in this what would have otherwise been the natural course of development of your code.
There is no way to improve the quality of software patents because once you've permitted the patenting of ideas- which is all software patents are- there exists no natural line such patents can't cross with enough lawyering and weasel words.
The dog and pony show the USPTO is putting on now is just because the general public is aware that software patents are insane, thanks mostly to NPR's show about patent trolls and the insane patent wars between Apple and Samsung over smartphones and rounded rectangles and every other twit and twiddle of an idea.
The only result that is ever going to keep you free to code and create in the US without fearing the day you get served and sued for damages is complete ban on all software patents. Since lawyers run the US to a greater degree than any other country on earth and the USPTO's bread and water is the fees people pay to patent things, there is no motivation on the part of anyone in power to just shut up and ban software patents.
All this is relevant to your question. No, you cannot meaningfully reach a safe harbor for code, non-trivially defined to include your future releases, away from litigation and software patents. Yes, it would be hard to patent the exact thing you opened source, but that doesn't actually do you that much good. No, this is not going to change in the near future in the US because banning software patents is not even on the table.
Your best solution is to not release code into countries that permit and have a history of enforcing software patents. I also suggest you fight like heck against the forces that seek to extend software patents into countries that currently ban them.
You can make a good living selling into those countries which permit software to be written without fear of lawyer-based terrorism. Releasing software into the US is just asking for trouble until and unless the laws which permit software patents change.
Sorry if this sounds harsh, but you're better off knowing the truth and acting upon it than being guided by a hopeful delusion and then having a rude awakening one fine day.
I hope you and everyone reading this realize I am actually being a good friend by speaking frankly and without prejudice or distortion on this topic.