Keyboard.release -- what if you release a key that is not pressed?

I am seeing some very strange behaviour in a USB HID application on a Leo and am really starting to scratch my head, as in "it can't do that!" Code excerpt:

  // if no motion, do nothing
  if (abs(distance) == abs(last_distance)) {
    return;
  }

  // distance is decreasing
  // if we are just starting to turn the bars back towards centre, stop the keypress right now
  if (abs(distance) < abs(last_distance)) {
    if (!turnBack) {
      Serial.println(F("Turning back, release steering keys"));
      Keyboard.release(KEY_LEFT_ARROW);
      Keyboard.release(KEY_RIGHT_ARROW);
      turnBack = 1;
      turnRight = 0;
      turnLeft = 0;
    }
    last_distance = distance;
    return;
  }

  // so you can only get here if distance is increasing.
     Serial.println(F("+motion, turnBack = 0"));
     turnBack = 0;

     ( ... )

seems fairly simple to me, but maybe I've been staring at it too long. anyway, in the serial monitor output I find this:

+motion, turnBack = 0
Turning back, release steering keys
Turning back, release steering keys
Turning back, release steering keys
Turning back, release steering keys
Turning back, release steering keys

Now, I may just be blind to something amazingly obvious, but I don't see how I can get that print statement multiple times in a row. It sets global boolean turnBack to 1, and if turnBack is 1 then we don't do that print statement again (that's the whole point of the turnBack flag).

However, I have to admit that I'm happily releasing both steering keys without regard to whether they are in fact pressed at this moment. I'm wondering whether there's some treacherous uncaught error in Keyboard.release that does weird things, writes on memory unsafely maybe, if you try to release a key that was not pressed. I've been googling but so far haven't found any discussion of "Keyboard.release of unpressed key".

The source code for Keyboard.release looks fairly innocuous:

	// Test the key report to see if k is present.  Clear it if it exists.
	// Check all positions in case the key is present more than once (which it shouldn't be)
	for (i=0; i<6; i++) {
		if (0 != k && _keyReport.keys[i] == k) {
			_keyReport.keys[i] = 0x00;
		}
	}

So I've always assumed that Keyboard.press of an already-pressed key, and Keyboard.release of a non-pressed key, are harmless. Could this assumption be dangerously wrong and explain why my fairly simple logic here seems to be going haywire? Or am I staring right at a really stupid coding error and just not seeing it?

Please post the entire sketch, not just a snippet. At the very least, post the entire function that those if's are contained in.

'sOK, as so often happens, as soon as I exposed my poor simple-minded code to possibly embarrassing public scrutiny, a few minutes later I saw the problem -- made a silly scoping error. great relief. I was, in fact, being blind to something amazingly obvious...