how to properly free a char **table in C

Posted by Samantha on Stack Overflow See other posts from Stack Overflow or by Samantha
Published on 2010-03-20T16:50:44Z Indexed on 2010/03/20 17:01 UTC
Read the original article Hit count: 402

Filed under:
|

Hello, I need your advice on this piece of code: the table fields options[0], options[1] etc... don't seem to be freed correctly. Thanks for your answers

int main()
{
  ....
  char **options;
  options = generate_fields(user_input);
  for(i = 0; i < sizeof(options) / sizeof(options[0]); i++)  {
    free(options[i]);
    options[i] = NULL;
  }

  free(options);
}

char ** generate_fields(char *) 
{
   char ** options = malloc(256*sizeof(char *));
   ...
   return options;

}

© Stack Overflow or respective owner

Related posts about c

    Related posts about malloc