I have a function that takes a pointer to char ** and fills it with strings (an array of strings, I think). * list_of_strings * memory is allocated inside the function.
char * *list_of_strings = NULL; fill_strings_with_stuff(&list_of strings); use_list_for_something(list_of_strings);
How can I free memory after I used strings? If i call
free(list_of_strings);
won't just free the actual pointers, and not the memory that each line uses? How to completely free memory
Just for clarity, the function looks something like this:
fill_strings_with_stuff(char *** list) { *list = malloc(AMOUNT); for (i = 0; i < SOMETHING; i++) { *(list + i) = malloc(LINE_LEN); *(list + i) = some_string_from_somewhere } }
source share