title: How to handle realloc when it fails due to memory?
body: <p>Question says it all but here is an example:</p>
  
  <pre><code>typedef struct mutable_t{
      int count, max;
      void **data;
  } mutable_t;
  
  
  void pushMutable(mutable_t *m, void *object)
  {
      if(m-&gt;count == m-&gt;max){
          m-&gt;max *= 2;
          m-&gt;data = realloc(m-&gt;data, m-&gt;max * sizeof(void*));
      }
      // how to handle oom??
      m-&gt;data[m-&gt;count++] = object;
  }
  </code></pre>
  
  <p>How can I handle running out of memory and not NULL out all of my data?</p>
  
  <p>edit - let's assume there is something which could be done e.g. free up some memory somewhere or at least tell the user "you can't do that - you're out of memory".  Ideally I would like to leave what was allocated there.</p>