Closed HammerProgrammer closed 3 years ago
Well, it is hard to say the timer is really the reason. According to the Swift code you are running re_main in concurrent queue so it is possible to have two re_main functions running simultaneously. Also, you are not unregistering the event handler registered here:
uag_event_register( { (agent, event, call, param, args) in
let e = String(cString: uag_event_str(event))
debugPrint("User Agent \(e)")
if let pointer = args {
let state = Unmanaged<SipState>.fromOpaque(pointer).takeUnretainedValue()
state.update(to: e)
}
}, self.statePointer)
I tried commenting out the event handler before but got the same result. I saw you opened a similar issue earlier did you solve it? How are you running the re_main loop if not inside a concurrent thread? Running on main blocks the UI for me
@HammerProgrammer
I saw you opened a similar issue earlier did you solve it?
I just do not use menu module which was the reason in my case.
How are you running the re_main loop if not inside a concurrent thread?
What I do is provide a single thread (a serial dispatch queue) for every re_main loop. Also, I make sure the previous re_main deallocates its resources before load resources and run the new re_main.
You may consider do not rerun the baresip stack at all until you know why do you need this.
please also check warnings. dont load modules that you dont need.
this issue is not a bug in baresip, but how it is used
I've removed all the unnecessary modules, and I have moved the re_main loop to a serial queue, re_cancel is being called and I can see the serial queue stops running before deinit. And everytime I relaunch the stack (load the viewcontroller again) my memory usage goes up more and more.
* thread #19, queue = 'baresip', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
* frame #0: 0x0000000102c25de3 baresip2nattempt`mem_deref(data=0x00007f9858512280) at mem.c:314:6 [opt]
frame #1: 0x0000000102c138ce baresip2nattempt`udp_timeout_handler [inlined] query_handler(q=0x00007f985852b270, err=0, hdr=0x0000000000000000, ansl=0x0000000000000000, authl=0x0000000000000000, addl=0x0000000000000000) at client.c:151:3 [opt]
frame #2: 0x0000000102c13897 baresip2nattempt`udp_timeout_handler(arg=0x00007f985852b270) at client.c:629 [opt]
frame #3: 0x0000000102c23ee6 baresip2nattempt`tmr_poll(tmrl=0x0000000102c51308) at tmr.c:115:3 [opt]
frame #4: 0x0000000102c25280 baresip2nattempt`re_main(signalh=<unavailable>) at main.c:1040:3 [opt]
frame #5: 0x0000000102bb5939 baresip2nattempt`closure #1 in SipClient.startLoop(self=0x0000600003b2e160) at SipClient.swift:156:30
frame #6: 0x0000000102bacbc0 baresip2nattempt`thunk for @escaping @callee_guaranteed () -> () at <compiler-generated>:0
frame #7: 0x0000000102f357ec libdispatch.dylib`_dispatch_call_block_and_release + 12
frame #8: 0x0000000102f369c8 libdispatch.dylib`_dispatch_client_callout + 8
frame #9: 0x0000000102f3d296 libdispatch.dylib`_dispatch_lane_serial_drain + 796
frame #10: 0x0000000102f3df67 libdispatch.dylib`_dispatch_lane_invoke + 439
frame #11: 0x0000000102f49de2 libdispatch.dylib`_dispatch_workloop_worker_thread + 882
frame #12: 0x00007fff60c8f4c0 libsystem_pthread.dylib`_pthread_wqthread + 314
frame #13: 0x00007fff60c8e493 libsystem_pthread.dylib`start_wqthread + 15
thread list
Process 1797 stopped
thread #1: tid = 0x11e42, 0x00007fff60c5231a libsystem_kernel.dylib`mach_msg_trap + 10, queue = 'com.apple.main-thread'
thread #7: tid = 0x11ea7, 0x00007fff60c5231a libsystem_kernel.dylib`mach_msg_trap + 10, name = 'com.apple.uikit.eventfetch-thread'
thread #9: tid = 0x11eda, 0x00007fff60c52356 libsystem_kernel.dylib`semaphore_wait_trap + 10, name = 'AMCP Logging Spool'
thread #15: tid = 0x122d8, 0x00007fff60c5231a libsystem_kernel.dylib`mach_msg_trap + 10, name = 'com.apple.audio.IOThread.client'
thread #18: tid = 0x1228b, 0x00007fff60c52356 libsystem_kernel.dylib`semaphore_wait_trap + 10
* thread #19: tid = 0x1259c, 0x0000000102c25de3 baresip2nattempt`mem_deref(data=0x00007f9858512280) at mem.c:314:6, queue = 'baresip', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
thread #20: tid = 0x1278d, 0x00007fff60c539be libsystem_kernel.dylib`__workq_kernreturn + 10
It no longer crashes. Also tmr_debug and mem_Debug no longer report any hanging timers or leaks. I had to call ua_stop_all(1) every time I wanted to close, even if re_main is not returning an error.
If I register or make a call and then close baresip and relaunch it again it will crash after some time has passed or if I try to register or make a call again. My code is here: https://pastebin.com/t7a80DFz and the log below