C语言中指针内存泄露,C语言中的指针和内存泄露

* Always use memset along with malloc, or always use calloc.

1.永远把memset和malloc一起使用,或者永远用calloc

* Whenever writing values to pointers, make sure you cross check the number of bytes available and number of bytes being written.

2.但写数据到指针所指的内存时,一定要检查可用空间的大小,和写入的字节数。

* Before assigning the pointers, make sure no memory locations will become orphaned.

3.在给一个指针赋值的时候,确定没有内存区域丢失。

* Whenever freeing the structured element (which in turn contains the pointer to dynamically allocated memory location), first traverse to the child memory location and start freeing from there, traversing back to the parent node.

4.当释放结构体成员的内存时(这个结构体有成员指针指向动态分配的内存),要先把子内存区域释放掉,再释放父内存区域。

* Always properly handle return values of functions returning references of dynamically allocated memory.

5.适当的处理返回指向动态分配的内存的指针的函数。(好绕嘴+_+)

* Have a corresponding free to every malloc.

6.对于每一个malloc都有一个对应的free

* Make sure you are not accessing null pointer.

7.确保你不会访问null指针。

http://www-128.ibm.com/developerworks/aix/library/au-toughgame/?ca=dgr-lnxw16PointersC

阅读(1281) | 评论(0) | 转发(1) |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值