惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Spread Privacy
Spread Privacy
大猫的无限游戏
大猫的无限游戏
F
Fortinet All Blogs
M
MIT News - Artificial intelligence
G
Google Developers Blog
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Help Net Security
V
Visual Studio Blog
WordPress大学
WordPress大学
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
Webroot Blog
Webroot Blog
Hugging Face - Blog
Hugging Face - Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
W
WeLiveSecurity
C
CERT Recently Published Vulnerability Notes
Y
Y Combinator Blog
S
Schneier on Security
Recent Announcements
Recent Announcements
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
宝玉的分享
宝玉的分享
T
Troy Hunt's Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
Microsoft Azure Blog
Microsoft Azure Blog
N
News and Events Feed by Topic
A
About on SuperTechFans
小众软件
小众软件
K
Kaspersky official blog
Help Net Security
Help Net Security
V2EX - 技术
V2EX - 技术
P
Proofpoint News Feed
S
Secure Thoughts
IT之家
IT之家
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
I
Intezer
NISL@THU
NISL@THU
GbyAI
GbyAI
P
Privacy & Cybersecurity Law Blog
T
Threatpost
C
Check Point Blog
Forbes - Security
Forbes - Security
C
Cisco Blogs
AI
AI
Recorded Future
Recorded Future
F
Full Disclosure

博客园 - sizzle

ruby函数回调的实现方法 软件单元测试之我见 在COM中使用数组参数-SafeArray[转载] 指针赋值 - sizzle - 博客园 进程的深度隐藏 文件隐藏 Windows下网络数据报的监听和拦截技术 三键屏蔽 键盘知识 如何获取当前程序文件的路径 Net Remoting[转自Bruce Zhang's Blog] 解码 XML 和 DTD 【读书笔记】[Effective C++第3版][第27条]尽量不要使用类型转换 P2P之UDP穿透NAT的原理与实现 CommandBinding用法 窗体显示中Form.Show()和Form.ShowDialog()的区别 一段高深代码--未解 使用C#注销/关闭计算机 TEA加密算法的C/C++实现
非空判断
sizzle · 2008-05-31 · via 博客园 - sizzle

今天调查内存泄漏,发现一块申请的堆未释放,于是加了一段释放代码
if(!pbuffer)
{
    TaskMemFree(pbuffer);
}

运行程序,发现仍然泄漏,继续检查其余代码,没发现问题,正在郁闷中,发现单步调试不能走到
释放代码内部,一看条件判断,晕!写了个无效代码,pbuffer为空时才会执行释放操作,改为
if(pbuffer)
{
    TaskMemFree(pbuffer);
}

问题解决!
看来写代码时显示判断还是保险些啊,如果当初写成
if(pbuffer != NULL)
{
    TaskMemFree(pbuffer);
}
就不会出现这样的问题了。

另外发现,堆分配时要做好配对,TaskMemAlloc要与TaskMemFree一起用,
New和Delete一起用,尤其在调用方法负责分配空间,调用者负责释放时,要
做好约定,有次用TaskMemAlloc分配的空间,但用Delete释放掉了,造成内
存泄漏,奇怪的是当时用Release版本,编译器不能检查出来,但用Debug版
本就提示出错了。