There are a couple of ways to do this. Well, if you are using software. I don't know about analog or standalone units.
You can punch in automatically in your DAW. Set the markers and set up the software to start recording at the markers. I can tell you how in Cubase, but I don't know for all the DAWs. For sure they are similar. Run through your lead solo part, mistakes and all. Then go back and set your marker to a measure or two before a mistake. Set it to automatically punch in at the marker. Then start before that at a comfortable point. Play the part again and it will start recording at the marker. Hopefully, you don't make the same mistake twice. Or 50 times, like me. After your done recording the part, you will have to edit the start and stops of the newly recorded part to fit in with the existing part.
Another way is to record the complete lead solo several times being sure not to repeat the same mistakes. After the first try, move the part out to beyond the song. Not deleting it, but so it's not in the song. Then record again the whole lead solo again. Snip the best sections from each take and piece them together.
I think some DAWs will let you stack takes on top of each other and you can edit them together into one composite part. I'm not sure how to do that.