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

#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

#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 Resolution: | Keywords: linker, memory Operating System: POSIX | leak, coverity Type of failure: Runtime | Architecture: Unknown/Multiple performance bug | Difficulty: Moderate (less Test Case: | than a day) Blocking: | Blocked By: | Related Tickets: -------------------------------------+------------------------------------- Changes (by nicolast): * keywords: linker, memory leak => linker, memory leak, coverity -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9021#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9021: [CID43168] 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 Resolution: | Keywords: linker, memory Operating System: POSIX | leak, coverity Type of failure: Runtime | Architecture: Unknown/Multiple performance bug | Difficulty: Moderate (less Test Case: | than a day) Blocking: | Blocked By: | Related Tickets: -------------------------------------+------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9021#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9021: [CID43168] rts/linker.c has a memory leak in the dlopen/dlerror code -------------------------------------+------------------------------------- Reporter: hgolden | Owner: hgolden Type: bug | Status: patch Priority: low | Milestone: 7.8.3 Component: Runtime System | Version: 7.8.2 Resolution: | Keywords: linker, memory Operating System: POSIX | leak, coverity Type of failure: Runtime | Architecture: Unknown/Multiple performance bug | Difficulty: Moderate (less Test Case: | than a day) Blocking: | Blocked By: | Related Tickets: -------------------------------------+------------------------------------- Changes (by hgolden): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9021#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9021: [CID43168] rts/linker.c has a memory leak in the dlopen/dlerror code -------------------------------------+------------------------------------- Reporter: hgolden | Owner: simonmar Type: bug | Status: patch Priority: low | Milestone: 7.8.3 Component: Runtime System | Version: 7.8.2 Resolution: | Keywords: linker, memory Operating System: POSIX | leak, coverity Type of failure: Runtime | Architecture: Unknown/Multiple performance bug | Difficulty: Moderate (less Test Case: | than a day) Blocking: | Blocked By: | Related Tickets: -------------------------------------+------------------------------------- Changes (by hgolden): * owner: hgolden => simonmar -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9021#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9021: [CID43168] rts/linker.c has a memory leak in the dlopen/dlerror code -------------------------------------+------------------------------------- Reporter: hgolden | Owner: simonmar Type: bug | Status: patch Priority: low | Milestone: 7.8.3 Component: Runtime System | Version: 7.8.2 Resolution: | Keywords: linker, memory Operating System: POSIX | leak, coverity Type of failure: Runtime | Architecture: Unknown/Multiple performance bug | Difficulty: Moderate (less Test Case: | than a day) Blocking: | Blocked By: | Related Tickets: -------------------------------------+------------------------------------- Comment (by hgolden): I am withdrawing my patch. The one posted to Coverity Scan was better. Please use that instead. (I don't know who wrote the Coverity Scan patch, but it may have been nicolast.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9021#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9021: [CID43168] rts/linker.c has a memory leak in the dlopen/dlerror code -------------------------------------+------------------------------------- Reporter: hgolden | Owner: simonmar Type: bug | Status: closed Priority: low | Milestone: 7.8.3 Component: Runtime System | Version: 7.8.2 Resolution: fixed | Keywords: linker, memory Operating System: POSIX | leak, coverity Type of failure: Runtime | Architecture: Unknown/Multiple performance bug | Difficulty: Moderate (less Test Case: | than a day) Blocking: | Blocked By: | Related Tickets: -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: patch => closed * resolution: => fixed Comment: That was me, thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9021#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9021: [CID43168] rts/linker.c has a memory leak in the dlopen/dlerror code -------------------------------------+------------------------------------- Reporter: hgolden | Owner: simonmar Type: bug | Status: merge Priority: low | Milestone: 7.8.3 Component: Runtime System | Version: 7.8.2 Resolution: fixed | Keywords: linker, memory Operating System: POSIX | leak, coverity Type of failure: Runtime | Architecture: Unknown/Multiple performance bug | Difficulty: Moderate (less Test Case: | than a day) Blocking: | Blocked By: | Related Tickets: -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: closed => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9021#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9021: [CID43168] rts/linker.c has a memory leak in the dlopen/dlerror code -------------------------------------+------------------------------------- Reporter: hgolden | Owner: simonmar Type: bug | Status: closed Priority: low | Milestone: 7.8.3 Component: Runtime System | Version: 7.8.2 Resolution: fixed | Keywords: linker, memory Operating System: POSIX | leak, coverity Type of failure: Runtime | Architecture: Unknown/Multiple performance bug | Difficulty: Moderate (less Test Case: | than a day) Blocking: | Blocked By: | Related Tickets: -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed Comment: This was already merged, it seems. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9021#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC