title: Malloc returns null when allocating space for the data structure
body: <p>Im need to create a dynamically allocated list of x,y points:</p>
  <pre><code>typedef struct
  {
      uint16_t x;
      uint16_t y;
  } point_t;
  </code></pre>
  <p>A series of points will be added to a structure:</p>
  <pre><code>typedef struct
  {
      uint32_t length;
      uint32_t size;
      point_t *pointlist;
  } pointlist_t;
  </code></pre>
  <p>So this code will allocate the first pointer to the pointslist_t structure but returns null when trying to allocate the point_t *.</p>
  <pre><code>bool pointInit(pointlist_t *pointlist)
  {
      // get storage for the points list
      pointlist = (pointlist_t *)malloc(sizeof(pointlist_t)); 
      if (pointlist == NULL)
      {
          free(pointlist);
          return false;
      }
  
      // now the list of points
      pointlist-&gt;pointlist = (point_t *)malloc(sizeof(point_t)); 
      if (pointlist-&gt;pointlist == NULL)
      {
          free(pointlist-&gt;pointlist);
          return false;
      }
      pointlist-&gt;length = 0;
      pointlist-&gt;size = 0;
      return true;
  }
  </code></pre>
  <p>In the main, I call the list:</p>
  <pre><code>    pointlist_t * mypointlist;
      pointInit(mypointlist);
  </code></pre>
  <p>I cant figure out why. Ideas?</p>