开发者社区> 问答> 正文

在gethostbyname_r后不管塞给它的hostent,是否会有内存泄漏问题?

我的中国 2017-11-30 18:07:53 770

在gethostbyname_r后不管塞给它的hostent,是否会有内存泄漏问题?

分享到
取消 提交回答
全部回答(2)
  • jesuszhu_
    2019-07-17 21:46:40

    这hostent难道不是你调用者自己分配的么?

    0 0
  • 我的中国
    2019-07-17 21:46:40

    You should print out the values of the pointers in that struct to find out the answer to your question. You'll discover that they all point to data inside the buffer you allocated.

    So a single free is all you need to free up all the memory.

    But this also means that you must not free that allocation until you've finished using or copying whatever data you're interested in.

    0 0
添加回答
+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

推荐文章