I have a multithreaded application that uses popen() for system calls.
Here is the snippet. I crashes in popen() (line 2 below).
1 fp = NULL;
2 if ((fp = popen(dnsCommand, "r")) == NULL) {
3 logPrint(errno, "*executeDNS: popen failed. Exiting...");
4 exitProcess(__func__, __LINE__);
}
I caught this under xcode debug and under cli lldb.
To replicate it I have to let it run for several hours, and this functions is called repeatedly during that time. I can't really tell the exact conditions that cause the crash.
The error messages is
Thread 43: EXC_BAD_ACCESS (code=1, address=0x3010000080e)
In this case dnsCommand is
dnsCommand char [200] "/Applications/NetBeez/bin/dig +noall +search +stats +comments xfinity.com 2>/dev/null"
Here is the backtrace
(lldb) bt
* thread #43, stop reason = EXC_BAD_ACCESS (code=1, address=0x3010000080e)
* frame #0: 0x00007ff803997d22 libsystem_c.dylib`popen + 478
frame #1: 0x000000010004b53e nbagentgdb`executeDNS(param=0x0000000128900000) at executeDNS.c:235:19
frame #2: 0x0000000100015778 nbagentgdb`executeTest(param=0x0000000128900000) at utilities.c:910:17
frame #3: 0x0000000100549cd0 libsystem_pthread.dylib`_pthread_start + 125
frame #4: 0x0000000100551cff libsystem_pthread.dylib`thread_start + 15
Here is where it crashed in popen()
0x7ff803997d1c <+472>: je 0x7ff803997d35 ; <+497>
0x7ff803997d1e <+474>: leaq -0x68(%rbp), %r12
-> 0x7ff803997d22 <+478>: movl 0x10(%rbx), %esi
0x7ff803997d25 <+481>: movq %r12, %rdi
0x7ff803997d28 <+484>: callq 0x7ff8039c68ee ; symbol stub for: posix_spawn_file_actions_addclose
0x7ff803997d2d <+489>: movq (%rbx), %rbx
And the variables
(lldb) register read rbx
rbx = 0x00000301000007fe
(lldb) register read esi
esi = 0x000aa000
I have the debugger hot right now on xcode, so if you need any other debug info lmk.
I suspect it crashes when the laptop goes to sleep, but is not consistent.
Any idea how to troubleshoot further?