when to carefully use free() to free up malloc() used memory?

后端 未结 3 1801
谎友^
谎友^ 2020-12-10 18:51

I read from many question here in SO and some other articles regarding free() function in c that frees the memory of unused variables. In my case, I have the following code

3条回答
  •  醉梦人生
    2020-12-10 19:36

    Since your function is returning strC, one presumes it must remain valid after the return of this function, thus this function must not free() that buffer. Once it's freed, the buffer is no longer valid so must not be used.

    Your caller is responsible for freeing it in this case.

提交回复
热议问题