fix memory leaks, clean up a bit, let the user recover in case of aborted image transfer.
Was some obvious memory leaks, some less obvious not-really-leaks-but-never-clearing memory leaks, some overly complex code.
It was also impossible to recover the terminal in case e. g. kitty's icat or img2sixel was stopped mid-transfer, so made ctrl+c reset the relevant state (I assume most people will press ctrl+c to try to recover control if it seems to hang).