diff --git a/ChangeLog b/ChangeLog
index 931c74e3338f41b268a6347725ba08ecd5655791..6be3279606f75336536e0c915126cafcfc7132db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -57,6 +57,9 @@ CVS code -
 	- For consistency, preserve placewewant if we didn't unjustify
 	  instead of setting it to 0. (DLR)
 - winio.c:
+  unget_kbinput()
+	- Free s after the wctomb() call, since we don't need it after
+	  that. (DLR)
   get_kbinput(), get_translated_kbinput(), get_ascii_kbinput(),
   get_untranslated_kbinput()
 	- Make the ascii_digits variables ints instead of size_t's,
diff --git a/src/winio.c b/src/winio.c
index 0ee50278a16ed31ad44b56d4b23eabd53bea00dc..2f6ca7953653796aabf2360bbad0891ff2a88d7f 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -125,6 +125,7 @@ void unget_kbinput(int kbinput, bool meta_key, bool func_key)
 	wchar_t wc = (wchar_t)kbinput;
 
 	i = wctomb(s, wc);
+	free(s);
 
 	if (i == -1)
 	    /* This wide character is unrecognized.  Send it back. */
@@ -133,7 +134,6 @@ void unget_kbinput(int kbinput, bool meta_key, bool func_key)
 	    for (; i > 0; i--)
 		ungetch(s[i - 1]);
 	}
-	free(s);
     } else
 	ungetch(kbinput);
     if (meta_key)