C language malloc release

problem description

use malloc to apply for space in a function in a C language project. Finally, the function returns the value saved in this space, that is, there is no space requested by free in the function, so do you need free outside the function?

related codes

char *test() {
    char *op = malloc(sizeof(char) * 16);
    ...
    return op;
 }
 
 int main() {
     printf("%s", test());
 }
CPP c
Oct.30,2021

needs to be released manually
malloc and free need to be used in pairs, otherwise it is easy to cause memory leak

Menu