Close the remote file handle if sftp_put_file's fstat fails.

Instead of abruptly returning from sftp_put_file in that situation, we
now send an FXP_CLOSE instead. Patch due to Tim Kosse.
Add a missing freeaddrinfo() in Unix sk_newlistener.

If we use getaddrinfo to translate the source IP address into a
sockaddr, then we need to freeaddrinfo the returned data later. Patch
due to Tim Kosse.
Fixes to memory management in the elliptic curve code.

There was an error-handling path testing the wrong variable; an
inappropriate call to ec_point_free in decodepoint() (in fact, that
function always gets passed a pointer to an ec_point structure that's
not a dynamically allocated block at all or not in its own right, so
we should have just cleared its contents without freeing the structure
itself); a missing return on an error path which would have caused the
same structure to be freed a second time; and two missing freebn in
ecdsa_sign.

Patch due to Tim Kosse.
Fix a handle leak in Windows PSFTP.

We were checking the return value of CreateThread for validity, but
not keeping it to free afterwards if it _was_ valid. Also, we weren't
closing ctx->event in the valid case either. Patch due to Tim Kosse.
Fix memory management in bignum_random_in_range.

We were allocating a new array in which to make up a random number
every time we went round the loop, and not freeing any of them. Now we
allocate a single array to use for all loop iterations, and clear and
free it properly afterwards.

Patch due to Tim Kosse.
Do an smemclr(bytes) in bignum_random_in_range.

It's used for sensitive data, so we shouldn't leave it lying around
after free.
Merge branch 'pre-0.64'
Repair GTK timer handling

The bug eventually makes PuTTY take 100% of a CPU.

timing.c:  This patch stops run_timers returning with a next timer
interval of zero ms. Which gets rid of the CPU spinning caused by other
parts of the code needing the timer to have passed.

unix/gtkwin.c: The code called from run_timers is likely to create a
new timer when it runs before timer_trigger adds the next timer that
run_timers returns. This would mean that two timers get scheduled
with gtk.

terminal.c: Make sure terminal.c doesn't waste CPU doing the text blink
timer when we don't have focus. Naturally the text blink and a blinking
cursor will resync when we regain focus.

NB: Windows calls 'term_set_focus' a lot .. Yes you still have focus
Repair GTK timer handling: Partial revert.

Something similar is now in SGT's base code.
Pango font performance update

This change improves the speed of the best case pango font
processing.  It removes multiple calls to pango_layout_set_text and
pango_layout_get_pixel_extents that were used to check that every prefix
string of a given draw_text is actually the correct size.

Instead the function now checks just once before painting the text
that the size of the whole region is correct. If it's not correct it
falls back to painting one character at a time immediatly rather than
optimistically trying lots of substrings; this normally improves the
draw time of complex screens and proportional fonts too.

If there are compensating layout issues within the string they won't
cause problems because terminal.c already has code to redraw any row
of text that was drawn as one operation if it's split.
Minimise, maximise, etc are as annoying as other terminal resize operations.

Note they ARE resize operations so treat them as such and disable them
if requested.
Add XTerm extensions for VTTEST and reverse BS

Codes to enable and disable the DECCOLM 132/80 column switching DEC
control and XTerm's reverse BS hack to 'pass' the vttest option 1.

This means that PuTTY uses the same modal hack as XTerm to pass the vttest
'end of line' test, (Actually the reverse part) and Thomas can stop lying
about PuTTY in the xterm FAQ.  The second part prevents the default xterm
'init' sequence from terminfo clearing the screen.

In addition most applications realise that terminal resizes are requests
and that you likely won't get what you ask for.  Programs (like vttest)
that use the sequence DECCOLM aren't so smart so the change is immediatly
enacted.
Adjust DEC-MCS character set.

U+2426 "␦" is defined as the substitution character in DEC-MCS

Note: dec_mcs is a 94 character set so 0xA0 and 0xFF are not defined in
a different way when it's mapped into GR.
Optimisation to delete windows code on unix

Changed is_dbcs_leadbyte to a macro on unix so the compiler knows
it's always zero.
Windows codepages do not have C1 controls

MS CP125X do NOT actually have any high control characters, the MS tables
show some of them but they are never interpreted by Microsoft software
and, as they have done before, MS will replace them by any new characters
that may be useful in the future.

Also eliminates as possible security risk where control characters are
not expected in Windows csets by host software.
Fix the scoasc translation on unix

There should be a set of VGA ROM characters in the first 32 positions
of the character set to match with Linux, scoansi and Windows PuTTY.
Function x11font_draw_text uses the UCS2 character set

Bugfix to stop the character set being repeated above U+10000
SCO Ansi Keyboard correction

The centre key (the '5') of the number pad should generate a CSI E for SCO.
Correct Window title character set on windows.

The characters are converted to unicode before use.
Changes to the internal usage of unicode areas for character set conversion.

The unix port is using the U+D800 range for the same jobs as the windows
port uses the U+F100 range. Set it to use the same range of characters.

Note: unlike windows this is ONLY used if the font doesn't have a
recognised character set so this change doesn't make the DTF range
compatible with the Linux console.

In a similar issue terminal.c is using the CSET_* codes for two different
tasks; the screen map characters and the line characters. Making the
distinction explicit should clarify things.

We now have a 32bit space for the characters so the hack of placing
the CSET_* code overlapping the surrogates is no longer required. We
can instead place them past the end of the valid unicode characters
(ie U+180000). Note I've chosen 0x180000 rather than 0x200000 to preserve
the compression of the scrollback.

Unfortunatly I can't do the same for the DTF range as it wouldn't work
for the UTF-16 platform. I can, however, move it to the "Low Surrogates"
area where it shouldn't interfere with the normal use of surrogates.

Added Linux DTF range (U+F000 -> CP437) explicitly into the emulation
because we no longer have the "happy coincidence" of the OEMCP being
mapped to U+F000. This means it could now be disabled for pure utf8 mode.