Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-3399] Leak of associated with error value #45987

Open
swift-ci opened this issue Dec 12, 2016 · 2 comments
Open

[SR-3399] Leak of associated with error value #45987

swift-ci opened this issue Dec 12, 2016 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself memory leak bug: Memory leak

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3399
Radar None
Original Reporter melifaro (JIRA User)
Type Bug

Attachment: Download

Environment

Swift 3
Toolchain: Xcode 8.1 (8B62)
macOS 10.12.1 (16B2657)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Leak
Assignee None
Priority Medium

md5: 74b4d6bd14414ff3b2a3b51003f3e721

Issue Description:

Consider following sample app (Cocoa).

There is only button clicking which leads to memory leak. The issue consistently reproducible (100% reproduction rate).

I am aware of leak caused by string interpolation - this seems to be a different one - at least there are no optionals used in the code of my sample app.

Code causing leak:

func doLeak() {

    do {
        
        let initialError = CustomError.fooError("Initial error message")
        
        switch initialError {
            
        case .barError:
            
            throw CustomError.fooError("barError")
            
        case .fooError(let message):
            
            let newMessage = "Wrap initial error: " + message
            throw CustomError.fooError(newMessage)
            
        }
        
    } catch {
        
        //it matters - commenting out line below prevents leak
        print(error)
    }
}

enum CustomError: Error {
    
    case fooError(String)
    
    //it matters - getting rid of 'barError' stops issue reproduction
    case barError
}

Leaked Objects

#   Address Size    Responsible Library Responsible Frame
_HeapBufferStorage<_StringBufferIVars, UInt16>  1   0x60000008e330  80 Bytes    libswiftCore.dylib  swift_slowAlloc
Malloc              32 Bytes    1   0x600000220240  32 Bytes    libswiftCore.dylib  swift_slowAlloc

"Malloc 32 Bytes" allocation stack:

   0 libsystem_malloc.dylib malloc_zone_malloc
   1 libsystem_malloc.dylib malloc
   2 libswiftCore.dylib swift_slowAlloc
   3 libswiftCore.dylib _swift_allocObject_
   4 libswiftCore.dylib _swift_allocObject_
   5 libswiftCore.dylib _TTSfq4n_n_n_d___TFVs13_StringBufferCfT8capacitySi11initialSizeSi12elementWidthSi_S_
   6 libswiftCore.dylib _TFVs11_StringCore12_copyInPlacefT7newSizeSi11newCapacitySi15minElementWidthSi_T_
   7 libswiftCore.dylib _TTSfq4gs_n___TFVs11_StringCore6appendfS_T_
   8 libswiftCore.dylib _TZFSSoi1pfTSSSS_SS
   9 SwiftLeaks ViewController.doLeak() -> () /depot/Learning/SwiftLeaks/SwiftLeaks/ViewController.swift:25
  10 SwiftLeaks ViewController.startButtonCLicked(Any) -> () /depot/Learning/SwiftLeaks/SwiftLeaks/ViewController.swift:8
  11 SwiftLeaks @objc ViewController.startButtonCLicked(Any) -> () /depot/Learning/SwiftLeaks/SwiftLeaks/ViewController.swift:0
  12 libsystem_trace.dylib _os_activity_initiate
  13 AppKit -[NSApplication(NSResponder) sendAction:to:from:]
  14 AppKit -[NSControl sendAction:to:]
  15 AppKit __26-[NSCell _sendActionFrom:]_block_invoke
  16 libsystem_trace.dylib _os_activity_initiate
  17 AppKit -[NSCell _sendActionFrom:]
  18 AppKit -[NSButtonCell _sendActionFrom:]
  19 libsystem_trace.dylib _os_activity_initiate
  20 AppKit -[NSCell trackMouse:inRect:ofView:untilMouseUp:]
  21 AppKit -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]
  22 AppKit -[NSControl mouseDown:]
  23 AppKit -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:]
  24 AppKit -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:]
  25 AppKit -[NSWindow(NSEventRouting) sendEvent:]
  26 AppKit -[NSApplication(NSEvent) sendEvent:]
  27 AppKit -[NSApplication run]
  28 AppKit NSApplicationMain
  29 SwiftLeaks main /depot/Learning/SwiftLeaks/SwiftLeaks/AppDelegate.swift:12
  30 libdyld.dylib start

"_HeapBufferStorage<_StringBufferIVars, UInt16>" allocation stack:

   0 libsystem_malloc.dylib malloc_zone_malloc
   1 libsystem_malloc.dylib malloc
   2 libswiftCore.dylib swift_slowAlloc
   3 libswiftCore.dylib swift_slowAlloc
   4 SwiftLeaks initializeBufferWithCopyOfBuffer for CustomError /depot/Learning/SwiftLeaks/SwiftLeaks/ViewController.swift:0
   5 libswiftCore.dylib _TTSgq5P__GVs10_TeeStreamSSVs7_Stdout_GS_SSS0__s16TextOutputStreams___TFs15_print_unlockedu0_R_s16TextOutputStreamrFTxRq__T_
   6 libswiftCore.dylib _TTSfq4g_gs_gs_n___TTSgq5GVs10_TeeStreamSSVs7_Stdout_GS_SSS0__s16TextOutputStreams___TFs6_printuRxs16TextOutputStreamrFTGSaP__9separatorSS10terminatorSS2toRx_T__merged
   7 libswiftCore.dylib _TTSfq4g_gs_gs_n___TTSgq5GVs10_TeeStreamSSVs7_Stdout_GS_SSS0__s16TextOutputStreams___TFs6_printuRxs16TextOutputStreamrFTGSaP__9separatorSS10terminatorSS2toRx_T_
   8 libswiftCore.dylib _TTSfq4g_gs_gs___TFs5printFTGSaP__9separatorSS10terminatorSS_T__merged
   9 libswiftCore.dylib _TTSfq4g_gs_gs___TFs5printFTGSaP__9separatorSS10terminatorSS_T_
  10 libswiftCore.dylib _TFs5printFTGSaP__9separatorSS10terminatorSS_T_
  11 SwiftLeaks ViewController.doLeak() -> () /depot/Learning/SwiftLeaks/SwiftLeaks/ViewController.swift:33
  12 SwiftLeaks ViewController.startButtonCLicked(Any) -> () /depot/Learning/SwiftLeaks/SwiftLeaks/ViewController.swift:8
  13 SwiftLeaks @objc ViewController.startButtonCLicked(Any) -> () /depot/Learning/SwiftLeaks/SwiftLeaks/ViewController.swift:0
  14 libsystem_trace.dylib _os_activity_initiate
  15 AppKit -[NSApplication(NSResponder) sendAction:to:from:]
  16 AppKit -[NSControl sendAction:to:]
  17 AppKit __26-[NSCell _sendActionFrom:]_block_invoke
  18 libsystem_trace.dylib _os_activity_initiate
  19 AppKit -[NSCell _sendActionFrom:]
  20 AppKit -[NSButtonCell _sendActionFrom:]
  21 libsystem_trace.dylib _os_activity_initiate
  22 AppKit -[NSCell trackMouse:inRect:ofView:untilMouseUp:]
  23 AppKit -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]
  24 AppKit -[NSControl mouseDown:]
  25 AppKit -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:]
  26 AppKit -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:]
  27 AppKit -[NSWindow(NSEventRouting) sendEvent:]
  28 AppKit -[NSApplication(NSEvent) sendEvent:]
  29 AppKit -[NSApplication run]
  30 AppKit NSApplicationMain
  31 SwiftLeaks main /depot/Learning/SwiftLeaks/SwiftLeaks/AppDelegate.swift:12
  32 libdyld.dylib start
@belkadan
Copy link
Contributor

@jckarter, I seem to remember us fixing a leak around either errors or printing. Does that sound familiar?

@jckarter
Copy link
Member

The ones I heard about, we fixed during 3.0. This might be a new one.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself memory leak bug: Memory leak
Projects
None yet
Development

No branches or pull requests

3 participants