title: ERR : double free or corruption (out) : C
body: <p>So here's my problem (<em>my questions are at the end</em>),</p>
  
  <p>I'm trying to initialize a list of "<em>Personne</em>" from a file.
  Here's the struct of "<em>Personne</em>" and the code i'm using :</p>
  
  <p>struct :</p>
  
  <pre><code>struct s_personne {
      char name[STRING];
      unsigned char password[SHA256_DIGEST_LENGTH];
      char *salt;
      char email[LSTRING];
  };
  </code></pre>
  
  <p>code :</p>
  
  <pre><code>int parseMyJsonPersonne(Plist l){
      FILE* fichier = NULL;
      char buffer[1024];
      char temp[502];
  
      struct json_object *parsed_json;
      struct json_object *name;
      struct json_object *password;
      struct json_object *salt;
      struct json_object *email;
  
      Personne p = (Personne)malloc(sizeof(Personne));
  
      fichier = fopen("../../data/Personne.json", "r");
      if (fichier != NULL) {
          while (fgets(temp, 502, fichier)!=NULL) {
              //printf("temp : %s", temp);
              strncat(buffer, temp, strlen(temp));
              if (strcmp(temp, "}\n")==0) {
  
                  //printf("Object find\n");
                  //printf("buffer : \n%s\n\n", buffer);
  
                  parsed_json = json_tokener_parse(buffer);
  
                  json_object_object_get_ex(parsed_json, "name", &amp;name);
                  json_object_object_get_ex(parsed_json, "password", &amp;password);
                  json_object_object_get_ex(parsed_json, "salt", &amp;salt);
                  json_object_object_get_ex(parsed_json, "email", &amp;email);
  
                  if (setPAll(p, (char *)json_object_get_string(name), (char *)json_object_get_string(password), (char *)json_object_get_string(salt), (char *)json_object_get_string(email))!=0) {
                      puts("Une ERREUR est survenue dans l'assemblage d'un objet (type=Personne)\n");
                      return 1;
                  }
                  if (addPersonne(p, l)!=0){
                      puts("Une ERREUR est survenue dans l'assemblage d'un objet (type=PList)\n");
                      return 1;
                  }
                  memset(buffer, '\0', 1024);
              }
          }
      }
      else {
          puts("Une ERREUR est survenue lors du chargement des différents comptes\n\n");
          return 1;
      }
  
      puts("Checkpoint 1 !!!");
      fclose(fichier);
      puts("Checkpoint 2 !!!");
  
      free(p);
      free(name);
      free(password);
      free(salt);
      free(email);
  
      return 0;
  }
  </code></pre>
  
  <p>The error occurs when I try to make the <strong>fclose(fichier);</strong> however I already know that the cause of the problem is when calling the <strong>setPAll</strong> function.
  This one calls the <strong>setPPassword</strong> funtion which has the following code:</p>
  
  <pre><code>int setPPassword(Personne p, char * password) {
      char stock[2];
      long val;
      printf("length of password (=64 ?) : %ld\n", strlen(password));
      printf("lenght p-&gt;password (=32 ?) : %d\n\n", SHA256_DIGEST_LENGTH);
      if (strlen(password) != 64) {
          puts("ERROR in setPPassword");
          return 1;
      }
      for(size_t i=0; i&lt;SHA256_DIGEST_LENGTH; i++) {
          stock[0]=password[2*i];
          stock[1]=password[2*i+1];
          printf("stock : %s\n", stock);
          val = strtol(stock, NULL, 16);
          p-&gt;password[i]=(unsigned char)val;
          printf("value in p-&gt;password at %ld : %02x\n",i, p-&gt;password[i]);
      }
      return 0;
  }
  </code></pre>
  
  <p>the problem is due to the <strong>p->password[i]=(unsigned char)val;</strong></p>
  
  <p>The problem here is that I really need my <em>p->password</em> to contain hex values.
  So is there a way to fix this error while initializing my <em>p->password</em> or is there a way to work around it by <em>changing my setPPassword function</em>?</p>