title: Occasional segmentation fault on malloc'd pointers
body: <p>I have the following code, in which whenever I try to free my malloc'ed memory I sometimes get a segmentation fault. This fault only occurs when freeing memory associated with some of my struct members (only on the nickname and beyond), meaning I never get a segmentation fault for <code>free(player-&gt;name)</code>, but about half the time I get segmentation faults from the other two frees (seeing how instruments is a null, it has no effect)</p>
  
  <pre><code>typedef struct player_t {
      char * name;
      char * nickname;
      Instrument * instruments;
      int instrumentAmount;
  } * Player;
  
  Player playerCreate(const char* name, const char* nickname,
  int maxInstruments) {
      Player one=malloc(sizeof(Player));
      if(one==NULL || !checkLegalName(name)|| !checkLegalName(nickname) ||   maxInstruments&lt;=0) {
          return NULL;
      }
  
      one-&gt;name=malloc(strlen(name)+1);
      one-&gt;nickname=malloc(strlen(name)+1);
  
      if(!one-&gt;name || !one-&gt;nickname) {
          playerDestroy(one);
          return NULL;
      }
  
      strcpy(one-&gt;name,name);
      strcpy(one-&gt;nickname,nickname);
      one-&gt;instrumentAmount=maxInstruments;
      one-&gt;instruments=NULL;
      return one;
  }
  </code></pre>
  
  <p>followed by this:</p>
  
  <pre><code>void playerDestroy(Player player) {
      if( !player) {
          return;
      }
  
      free(player-&gt;name);
      free(player-&gt;nickname); // this is where it happens.
      free(player-&gt;instruments);
      free(player);
  }
  </code></pre>
  
  <p>Any help in solving this would be appreciated.</p>