you have to file your song and send it to a special place where they protect it from copyright infringment (I thing it's called ascap in the US, in france, it's called SACEM) It's 20 dollars per song in the US, and it's a 100 dollars in france for as many as you want.
You have to be careful with the terms used. If you steal a lick from a solo, when you improvise, it's not bad, otherwise, we would owe a lot to BB king and Hendrix, and Van halen etc... What you can't do is steal the theme of the song. The stuff about the four bars is false... If someone can recognize the theme, it's considered as if you had stolen it.
There's something about coming up with a theme that could be already an existing song (it's rather unusual, but it could happen). If you can prove that you haven't been exposed to the song, then you might get away unharmed, otherwise you have to pay royalties...