Record and playback has echo/feedback
Feedback squeal or echo is pretty much the expected result of the given code.
This program just takes audio in from the microphone and sends it back out through the speaker.  If the speaker is loud enough, the audio the microphone picks up from the speaker will be louder than what was sent to the speaker - with each go around, it gets louder.  This produces the infamous feedback squeal.  If the delay is long enough, you an echo that gets louder and louder instead of a squeal.

You may also have a problem with your sound card configuration.  Some sound cards allow you to send the microphone input straight to the speaker output so that you can use headphones to monitor the recoring live.  If that is active on your sound card, then that may contribute to the feedback.  This will more likely cause a high pitched squeal that is independent of the length of the buffer.

To break the feedback, do the following:


Check that your sound card isn't routing the microphone straight to the speaker. (Stop your program and talk into the microphone.  If you hear your voice coming out of the speaker then you need to fix this in your sound card mixer.)
User headphones instead of a speaker.
Turn the speaker volume down or lower the microphone sensitivity (both can be done through the mixer, speaker can also be done on the speaker with the volume control.)