diff --git a/Changelog b/Changelog
--- a/Changelog
+++ b/Changelog
@@ -1,16 +1,25 @@
-1.3.0.4
+1.3.0.5 (2017-07-07)
 
+	* Fix segfault in registerHotplugCallback caused by a double-free.
+	  The fix was to increment the reference count of the USB device that
+	  was passed to the HotplugCallback.
+
+	  Thanks to Ryan Mulligan and Ian Kane for reporting and investigating this bug.
+
+
+1.3.0.4 (2016-07-02)
+
 	* Support GHC-8.0.1.
 	* Support vector-0.11.
         * Add Travis-CI integration.
 
 
-1.3.0.3
+1.3.0.3 (2015-05-06)
 
 	* Fix incorrect direction in controlRead.
 
 
-1.3.0.2
+1.3.0.2 (2015-05-02)
 
 	* Support GHC-7.10.2.
 
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2009–2012 Bas van Dijk
+Copyright (c) 2009–2017 Bas van Dijk
 
 All rights reserved.
 
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,43 +1,2 @@
-#! /usr/bin/env runhaskell
-
-{-# LANGUAGE NoImplicitPrelude #-}
-
-module Main (main) where
-
-
--------------------------------------------------------------------------------
--- Imports
--------------------------------------------------------------------------------
-
--- from base
-import Control.Monad       ( (>>), return )
-import System.IO           ( IO )
-
--- from cabal
-import Distribution.Simple ( defaultMainWithHooks
-                           , simpleUserHooks
-                           , UserHooks(haddockHook)
-                           , Args
-                           )
-
-import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..) )
-import Distribution.Simple.Program        ( userSpecifyArgs )
-import Distribution.Simple.Setup          ( HaddockFlags )
-import Distribution.PackageDescription    ( PackageDescription(..) )
-
-
--------------------------------------------------------------------------------
--- Cabal setup program which sets the CPP define '__HADDOCK __' when haddock is run.
--------------------------------------------------------------------------------
-
-main :: IO ()
-main = defaultMainWithHooks hooks
-  where
-    hooks = simpleUserHooks { haddockHook = haddockHook' }
-
--- Define __HADDOCK__ for CPP when running haddock.
-haddockHook' :: PackageDescription -> LocalBuildInfo -> UserHooks -> HaddockFlags -> IO ()
-haddockHook' pkg lbi =
-  haddockHook simpleUserHooks pkg (lbi { withPrograms = p })
-  where
-    p = userSpecifyArgs "haddock" ["--optghc=-D__HADDOCK__"] (withPrograms lbi)
+import Distribution.Simple
+main = defaultMain
diff --git a/System/USB.hs b/System/USB.hs
--- a/System/USB.hs
+++ b/System/USB.hs
@@ -6,7 +6,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD-style (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 --
diff --git a/System/USB/Base.hs b/System/USB/Base.hs
--- a/System/USB/Base.hs
+++ b/System/USB/Base.hs
@@ -803,7 +803,7 @@
 --                                  mbVendorId
 --                                  mbProductId
 --                                  mbDevClass
---                                  (\dev event ->
+--                                  (\\dev event ->
 --                                     tryPutMVar mv (dev, event) $>
 --                                       DeregisterThisCallback)
 --     (dev, _event) <- takeMVar mv
@@ -874,7 +874,7 @@
            -> Ptr ()
            -> IO CInt
         cb _ctxPtr devPtr ev _userData = do
-          dev <- mkDev ctx devPtr
+          dev <- mask_ $ c'libusb_ref_device devPtr >>= mkDev ctx
           status <- hotplugCallback dev (HotplugEvent ev)
 
           case status of
diff --git a/System/USB/Descriptors.hs b/System/USB/Descriptors.hs
--- a/System/USB/Descriptors.hs
+++ b/System/USB/Descriptors.hs
@@ -6,7 +6,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB.Descriptors
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD3 (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 --
diff --git a/System/USB/DeviceHandling.hs b/System/USB/DeviceHandling.hs
--- a/System/USB/DeviceHandling.hs
+++ b/System/USB/DeviceHandling.hs
@@ -6,7 +6,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB.Devices
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD3 (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 --
diff --git a/System/USB/Enumeration.hs b/System/USB/Enumeration.hs
--- a/System/USB/Enumeration.hs
+++ b/System/USB/Enumeration.hs
@@ -6,7 +6,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB.Devices
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD3 (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 --
diff --git a/System/USB/Exceptions.hs b/System/USB/Exceptions.hs
--- a/System/USB/Exceptions.hs
+++ b/System/USB/Exceptions.hs
@@ -6,7 +6,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB.Exceptions
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD3 (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 --
diff --git a/System/USB/IO.hs b/System/USB/IO.hs
--- a/System/USB/IO.hs
+++ b/System/USB/IO.hs
@@ -7,7 +7,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB.IO
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD3 (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 --
@@ -61,7 +61,7 @@
 #endif
     ) where
 
-#ifdef __HADDOCK__
+#ifdef __HADDOCK_VERSION__
 #ifdef HAS_EVENT_MANAGER
 #if MIN_VERSION_base(4,4,0)
 import GHC.Event
diff --git a/System/USB/IO/StandardDeviceRequests.hs b/System/USB/IO/StandardDeviceRequests.hs
--- a/System/USB/IO/StandardDeviceRequests.hs
+++ b/System/USB/IO/StandardDeviceRequests.hs
@@ -9,7 +9,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB.IO.StandardDeviceRequests
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD3 (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 --
@@ -80,7 +80,7 @@
                                  , InterfaceNumber
                                  , InterfaceAltSetting
                                  )
-#if __HADDOCK__
+#ifdef __HADDOCK_VERSION__
 import qualified System.USB.DeviceHandling as USB ( setConfig, getConfig )
 #endif
 
diff --git a/System/USB/IO/Transfers.hs b/System/USB/IO/Transfers.hs
--- a/System/USB/IO/Transfers.hs
+++ b/System/USB/IO/Transfers.hs
@@ -7,7 +7,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB.IO.Transfers
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD3 (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 -- Stability   :  Experimental
@@ -161,7 +161,7 @@
     , getIsochronousWriteTransferPackets
     ) where
 
-#ifdef __HADDOCK__
+#ifdef __HADDOCK_VERSION__
 #if MIN_VERSION_base(4,4,0)
 import GHC.Event
 #else
diff --git a/System/USB/Initialization.hs b/System/USB/Initialization.hs
--- a/System/USB/Initialization.hs
+++ b/System/USB/Initialization.hs
@@ -7,7 +7,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB.Init
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD3 (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 --
diff --git a/System/USB/Misc.hs b/System/USB/Misc.hs
--- a/System/USB/Misc.hs
+++ b/System/USB/Misc.hs
@@ -7,7 +7,7 @@
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  System.USB.Misc
--- Copyright   :  (c) 2009–2014 Bas van Dijk
+-- Copyright   :  (c) 2009–2017 Bas van Dijk
 -- License     :  BSD3 (see the file LICENSE)
 -- Maintainer  :  Bas van Dijk <v.dijk.bas@gmail.com>
 --
diff --git a/usb.cabal b/usb.cabal
--- a/usb.cabal
+++ b/usb.cabal
@@ -1,10 +1,10 @@
 name:          usb
-version:       1.3.0.4
+version:       1.3.0.5
 cabal-version: >=1.6
-build-type:    Custom
+build-type:    Simple
 license:       BSD3
 license-file:  LICENSE
-copyright:     2009–2014 Bas van Dijk <v.dijk.bas@gmail.com>
+copyright:     2009–2017 Bas van Dijk <v.dijk.bas@gmail.com>
 author:        Bas van Dijk <v.dijk.bas@gmail.com>
 maintainer:    Bas van Dijk <v.dijk.bas@gmail.com>
 homepage:      http://basvandijk.github.com/usb
@@ -50,6 +50,12 @@
                .
                * \"USB in a NutShell\" (<http://www.beyondlogic.org/usbnutshell/usb1.htm>).
 
+tested-with: GHC == 7.4.1,  GHC == 7.4.2,
+             GHC == 7.6.1,  GHC == 7.6.2,  GHC == 7.6.3,
+             GHC == 7.8.1,  GHC == 7.8.2,  GHC == 7.8.3, GHC == 7.8.4
+             GHC == 7.10.1, GHC == 7.10.2, GHC == 7.10.3
+             GHC == 8.0.1,  GHC == 8.0.2
+             GHC == 8.3
 
 extra-source-files: README.markdown, Changelog, default.nix, shell.nix
 
@@ -60,11 +66,11 @@
 Library
   GHC-Options: -Wall
 
-  build-depends: base                 >= 4     && < 4.10
+  build-depends: base                 >= 4     && < 4.11
                , bindings-libusb      >= 1.4.5 && < 1.5
                , bytestring           >= 0.9   && < 0.11
                , text                 >= 0.5   && < 1.3
-               , vector               >= 0.5   && < 0.12
+               , vector               >= 0.5   && < 0.13
 
   exposed-modules: System.USB
                    System.USB.Initialization
