You need to stop the LocalMediaStream object by executing its stop() method. I had similar problems. What you need to do is:
Keep a reference to the LocalMediaStream in the onSuccess callback function of the getUserMedia() execution:
var localStream;
onUserMediaSuccess = function(stream) {
// attach to a video element
...
// keep a reference
localStream = stream;
};
Stop the LocalMediaStream where needed:
localStream.stop();
More info in my own question (and answer).