How to free a struct that contains only pointers

前端 未结 4 1730
南笙
南笙 2020-12-28 09:36

I have a struct which you see below:

typedef struct _List {
    Person *person; // pointer for people list
    DoList *do; // Kinda timer, for checking list          


        
4条回答
  •  死守一世寂寞
    2020-12-28 10:16

    void free_mystruct(struct_List *a_ptr){
      free(a_ptr->person);
      free(a_ptr->do);
      free(a_ptr);
    }
    

    if you used malloc to initially allocate memory.

提交回复
热议问题