在重复多次的函数中释放各种指针

deallocating various pointers in a function that repeats several times

我有一个发送结构值的 void 函数

my func' 重复了几次。结构成员是动态分配的。那么我怎样才能释放它们呢?

我想如果我在 func' 本身中释放它们,它会破坏已发送的结构对象。

void func(){

    typedef struct ENTRY {
        int entry_num;
        char* English_term;
        char** translations;
        enum types type;
    }ENTRY;


    ENTRY new_entry = { .entry_num = 0,
        .English_term = temp,
        .translations = (char**)malloc(tr_amnt * sizeof(char*)),
        .type = 0
    }
    ...
    ... 

    another_function(new_entry);

    // free all pointers?

}

是的,因为您没有 return 以任何方式从函数中获取指针(既不通过 return 语句也不通过函数参数),您可以 free() 分配的这些指针指向的内存。

预计 another_function() 将拥有自己传递的参数副本,如果需要保留函数调用之外的值。