Leonardo fails to shut down when power is removed while TTL inputs are high

I have a problem with an Arduino Leonardo. I use the USB port to upload sketches and supply power to the device, and a number of digital and analog pins to read TTL signals from another device. When I unplug the USB, I expect the Arduino to shut down, and when I plug it back in, I expect it to boot again. This works fine on the condition that all the TTL signals are low. However, when one or several of the TTL signals are high, unplugging the USB does not shut down the Arduino. It appears that somehow it continues to be powered by the 5 volts that are present at some of its digital or analog input/output pins. If enough pins are high, it seems to continue running the sketch normally, and when only one or a few pins are high, it starts behaving erratically. In order to force it to reset, I have to unplug all the TTL inputs as well as the USB, which is not practical. Do you have any idea why this might be happening? Do I have a defective Arduino? Is there any way to make sure it shuts down when the USB is disconnected, no matter the state of its input lines?

Power can leak into a chip from I/O pins. Usually this is not a problem because the devices attached to the Arduino are usually powered by the same source and turned off at the same time. If the external devices have external power you can use opto-isolators to keep the external power separate from the Arduino power.

For what it's worth: I have found a cheap, simple, and space-saving solution for this. All it needs is a voltage supervisor chip with active low output and 4.5 volts reset threshold, for example type MCP130-450HI/TO. Place this between the "GND", "5V", and "RST" pins on the Arduino or any of the shields in the stack, and the problem is solved.