diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,14 @@
 
+5.39
+----
+
+Package changes:
+* Now builds with `mtl-2.3.*`.
+
+Bug fixes:
+* Fixed a long-standing issue where unused input on stdin could cause a
+  memory error and a crash when Vty was being initialized. (#266)
+
 5.38
 ----
 
diff --git a/src/Graphics/Vty/Config.hs b/src/Graphics/Vty/Config.hs
--- a/src/Graphics/Vty/Config.hs
+++ b/src/Graphics/Vty/Config.hs
@@ -111,7 +111,7 @@
 import Control.Applicative hiding (many)
 
 import Control.Exception (catch, IOException, Exception(..), throwIO)
-import Control.Monad (liftM, guard, void)
+import Control.Monad (liftM, guard, void, when)
 
 import qualified Data.ByteString as BS
 #if !(MIN_VERSION_base(4,8,0))
@@ -132,6 +132,7 @@
                         )
 import System.Environment (lookupEnv)
 import System.FilePath ((</>), takeDirectory)
+import System.IO (Handle, BufferMode(..), hReady, hSetBuffering, hGetChar, stdin)
 import System.Posix.IO (stdInput, stdOutput)
 import System.Posix.Types (Fd(..))
 import Foreign.C.Types (CInt(..), CChar(..))
@@ -293,6 +294,7 @@
       Nothing -> throwIO VtyMissingTermEnvVar
       Just t -> do
         mcolorMode <- detectColorMode t
+        flushInput stdin
         return defaultConfig
           { vmin               = Just 1
           , mouseMode          = Just False
@@ -486,3 +488,19 @@
                    Nothing -> do
                        appendFile configPath directive
                        return ConfigurationModified
+
+flushInput :: Handle -> IO ()
+flushInput h = do
+    hSetBuffering h NoBuffering
+    whileM $ consume h
+
+whileM :: (Monad m) => m Bool -> m ()
+whileM act = do
+    continue <- act
+    when continue $ whileM act
+
+consume :: Handle -> IO Bool
+consume h = do
+    avail <- hReady h
+    when avail $ void $ hGetChar h
+    return avail
diff --git a/src/Graphics/Vty/Input.hs b/src/Graphics/Vty/Input.hs
--- a/src/Graphics/Vty/Input.hs
+++ b/src/Graphics/Vty/Input.hs
@@ -154,6 +154,7 @@
                             , vmin = Just _
                             , vtime = Just _
                             , .. } = do
+
     terminal <- Terminfo.setupTerm termName
     let inputOverrides = [(s,e) | (t,s,e) <- inputMap, t == Nothing || t == Just termName]
         activeInputMap = classifyMapForTerm termName terminal `mappend` inputOverrides
diff --git a/tools/CrashFix.hs b/tools/CrashFix.hs
new file mode 100644
--- /dev/null
+++ b/tools/CrashFix.hs
@@ -0,0 +1,29 @@
+module Main (main) where
+
+import Control.Monad (when, void)
+import Graphics.Vty
+import System.IO
+
+main :: IO ()
+main = do
+    flushInput stdin
+    vty <- mkVty defaultConfig
+    shutdown vty
+
+flushInput :: Handle -> IO ()
+flushInput h = do
+    mode <- hGetBuffering h
+    hSetBuffering h NoBuffering
+    whileM $ consume h
+    hSetBuffering h mode
+
+whileM :: (Monad m) => m Bool -> m ()
+whileM act = do
+    continue <- act
+    when continue $ whileM act
+
+consume :: Handle -> IO Bool
+consume h = do
+    ava <- hReady h
+    when ava $ void $ hGetChar h
+    pure ava
diff --git a/tools/CrashTest.hs b/tools/CrashTest.hs
new file mode 100644
--- /dev/null
+++ b/tools/CrashTest.hs
@@ -0,0 +1,8 @@
+module Main (main) where
+
+import Graphics.Vty
+
+main :: IO ()
+main = do
+    vty <- mkVty defaultConfig
+    shutdown vty
diff --git a/vty.cabal b/vty.cabal
--- a/vty.cabal
+++ b/vty.cabal
@@ -1,5 +1,5 @@
 name:                vty
-version:             5.38
+version:             5.39
 license:             BSD3
 license-file:        LICENSE
 author:              AUTHORS
@@ -109,6 +109,32 @@
                        cbits/set_term_timing.c
                        cbits/get_tty_erase.c
                        cbits/mk_wcwidth.c
+
+executable vty-crash-test
+  main-is:             CrashTest.hs
+  hs-source-dirs:      tools
+  default-language:    Haskell2010
+  ghc-options:         -threaded -Wall
+
+  if !impl(ghc >= 8.0)
+    build-depends:     semigroups >= 0.16
+
+  build-depends:       base,
+                       vty,
+                       directory,
+                       filepath
+
+executable vty-crash-fix
+  main-is:             CrashFix.hs
+  hs-source-dirs:      tools
+  default-language:    Haskell2010
+  ghc-options:         -threaded -Wall
+
+  if !impl(ghc >= 8.0)
+    build-depends:     semigroups >= 0.16
+
+  build-depends:       base,
+                       vty
 
 executable vty-build-width-table
   main-is:             BuildWidthTable.hs
