0

这是简单的代码:

#include <stdio.h>
#include <stdlib.h>

void cleanUp(){
    printf("I have to do free up memory\n");
}

int main(){

    char *temp;

    temp = (char *)malloc(10*sizeof(char)); 

    atexit(cleanUp);

    exit(0);

    free(temp);

    return 0;
}

当程序退出时,我怎样才能释放内存。函数“cleanUp”没有参数。那么如何释放函数“cleanUp”中的内存以防止内存泄漏。

4

0 回答 0