title: Problem with realloc of **struct
body: <p>I have a problem with realloc function in C. I'm passing you a code bellow:</p>
  
  <pre><code>typedef struct _Pool Pool;
  typedef struct _Item Item;
  
  struct _Pool {
      Item ** items;
      unsigned int itemsCount;
      unsigned int poolSize;
      unsigned int poolStep;
  };
  
  struct _Item {
      char * file; 
      unsigned int lenOfFilePath;
      unsigned int x;
  };
  
  void Pool_insert(Pool ** pool, Item * item)
  {       
      if ((*pool)-&gt;itemsCount + 1 == (*pool)-&gt;poolSize)
      {
          (*pool)-&gt;items = realloc((*pool)-&gt;items, sizeof(Item *)*((*pool)-&gt;poolSize + (*pool)-&gt;poolStep));;
          if (!(*pool)-&gt;items) return;
          (*pool)-&gt;poolSize += (*pool)-&gt;poolStep;
      }
  
      (*pool)-&gt;items[(*pool)-&gt;itemsCount++] = item;
  }
  </code></pre>
  
  <p>I'm not sending the first allocation code but if I increase the number of items that I'm using there everything works fine. When I call realloc I'm getting such error:</p>
  
  <blockquote>
    <p>malloc: *** error for object 0x19dba8:
    pointer being reallocated was not
    allocated</p>
  </blockquote>
  
  <p>Could you please help me to solve my problem?</p>
  
  <hr>
  
  <p>Here is the creation method for Pool:</p>
  
  <pre><code>void Pool_create(Pool ** pool, unsigned int poolSize)
  {   
      unsigned int poolMemSize = sizeof(Pool) + sizeof(Item *)*poolSize;
      *pool = malloc(poolMemSize);
      if (!*pool) return;
      memset(*pool,0,poolMemSize);
  
      (*pool)-&gt;itemsCount = 0;
      (*pool)-&gt;poolSize = poolSize;
      (*pool)-&gt;poolStep = POOL_STEP;
  
      (*pool)-&gt;items = (Item **)((char*)(*pool) + sizeof(Pool));
      if(!(*pool)-&gt;items) return;
      memset((*pool)-&gt;items, 0, sizeof(Item *) * poolSize);
  }
  </code></pre>
  
  <p>Like I told, if I want for example insert 1000 Items and allocate the memory by create function then everything works fine if I declare start Pool size for 100 elements and then I want to realloc Items I get the error.</p>
  
  <p>Thank you very much for such quick answer.</p>