title: C code on Linux under gdb runs differently if run standalone?
body: <p>I have built a plain C code on Linux (Fedora) using code-sorcery tool-chain. This is for ARM Cortex-A8 target. This code is running on a Cortex A8 board, running embedded Linux.</p>
  
  <p>When I run this code for some test case, which does dynamic memory allocation (<code>malloc</code>) for some large size (10MB), it crashes after some time giving error message as below:</p>
  
  <pre><code>select 1 (init), adj 0, size 61, to kill
  select 1030 (syslogd), adj 0, size 64, to kill
  select 1032 (klogd), adj 0, size 74, to kill
  select 1227 (bash), adj 0, size 378, to kill
  select 1254 (ppp), adj 0, size 1069, to kill
  select 1255 (TheoraDec_Corte), adj 0, size 1159, to kill
  send sigkill to 1255 (TheoraDec_Corte), adj 0, size 1159
  Program terminated with signal SIGKILL, Killed.
  </code></pre>
  
  <p>Then, when I debug this code for the same test case using gdb built for the target, the point where this dynamic memory allocation happens, code fails to allocate that memory and <code>malloc</code> returns <code>NULL</code>. But during normal stand-alone run, I believe <code>malloc</code> should be failing to allocate but it strangely might not be returning <code>NULL</code>, but it crashes and the OS kills my process.</p>
  
  <ol>
  <li>Why is this behaviour different when run under gdb and when without debugger?</li>
  <li>Why would <code>malloc</code> fails yet not return a <code>NULL</code>. Could this be possible, or the reason for the error message I am getting is else?</li>
  <li>How do I fix this?</li>
  </ol>
  
  <p>thanks,</p>
  
  <p>-AD</p>