How can I debug a C application that does not crash when attached with `gdb` and `run` inside of gdb? 

It crashes consistently when run standalone - even the same debug build!

---

A few of us are getting this error with a C program written for BSD/Linux, and we are compiling on macOS with OpenSSL.

```
app(37457,0x7000017c7000) malloc: *** mach_vm_map(size=13835058055282167808) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
ERROR: malloc(buf->length + 1) failed!

```

I know, not helpful. 

Recompiling the application with `-g -rdynamic` gives the same error. Ok, so now we know it isn't because of a release build as it continues to fail.

It works when running within a `gdb` debugging session though!!

```
$ sudo gdb app
(gdb) b malloc_error_break
Function "malloc_error_break" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (malloc_error_break) pending.
(gdb) run -threads 8
Starting program: ~/code/app/app -threads 8
[New Thread 0x1903 of process 45436]
warning: unhandled dyld version (15)

```

And it runs for hours. CTRL-C, and run `./app -threads 8` and it crashes after a second or two (a few million iterations). 

Obviously there's an issue within one of the threads. But those workers for the threads are pretty big (a few hundred lines of code). Nothing stands out.

Note that the threads iterate over loops of about 20 million per second. 

* macOS 10.12.3
* Homebrew w/GNU gcc and openssl (linking to crypto)

---

Ps, not familiar with C too much - especially any type of debugging. Be kind and expressive/verbose in answers. :)