Freeing memory which has been allocated to an array of char pointers (strings). Do I have to free each string or just the “main” pointer?

后端 未结 4 911
春和景丽
春和景丽 2021-02-15 11:26

I have a function that takes a pointer to a char ** and fills it with strings (an array of strings I guess). *list_of_strings* is allocated memory inside the function.



        
4条回答
  •  南方客
    南方客 (楼主)
    2021-02-15 12:05

    Basically, there's a rule of thumb to allocating and freeing: You need to call as many free() as you called malloc(). It's as simple as that. In every other case you got yourself a memory leak.

提交回复
热议问题