What is the correct usage of realloc() when it fails and returns NULL?

后端 未结 4 1855
Happy的楠姐
Happy的楠姐 2020-12-31 04:39

Can anyone summarize what is the correct usage of realloc()?

What do you do when realloc() fails?

From what I have seen so far, it

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 05:15

    From http://www.c-faq.com/malloc/realloc.html

    If realloc cannot find enough space at all, it returns a null pointer, and leaves the previous region allocated.

    Therefore you would indeed need to free the previously allocated memory still.

提交回复
热议问题