[GHC] #9021: rts/linker.c has a memory leak in the dlopen/dlerror code

GHC ghc-devs at haskell.org
Wed Apr 23 02:25:55 UTC 2014


#9021: rts/linker.c has a memory leak in the dlopen/dlerror code
-------------------------------------+-------------------------------------
       Reporter:  hgolden            |             Owner:  hgolden
           Type:  bug                |            Status:  new
       Priority:  low                |         Milestone:  7.8.3
      Component:  Runtime System     |           Version:  7.8.2
       Keywords:  linker, memory     |  Operating System:  POSIX
  leak                               |   Type of failure:  Runtime
   Architecture:  Unknown/Multiple   |  performance bug
     Difficulty:  Moderate (less     |         Test Case:
  than a day)                        |          Blocking:
     Blocked By:                     |
Related Tickets:                     |
-------------------------------------+-------------------------------------
 The Coverity Scan of ghc highlighted a memory leak (CID 43168) in the
 internal_dlopen function in rts/linker.c. I wrote this code originally and
 I recall that there was a memory leak in certain situations, but I didn't
 fix it at the time because it seemed to be rather minor and only would
 occur in unusual cases. However, since Coverity identified it, I have
 thought about it and know how to fix the leak, so I am creating this
 ticket.

 The leak occurs because the error message from dlerror must be copied to
 allocated memory, since the dlerror message is not guaranteed to be
 stable, and its code is not guaranteed to be reentrant (see POSIX
 dlopen/dlerror documentation). As I originally coded Trac ticket #2615, I
 didn't bother to free the allocated memory. The fix is to make sure that
 the allocated memory is freed once the error message is displayed. Memory
 is only allocated if there is an error, so it must be freed only when an
 error has been identified and processed. As far as I know, this bug only
 exists on a POSIX system.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9021>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list