作者dozer (rezod)
看板LinuxDev
标题[问题] error handling
时间Mon Dec 18 20:43:08 2006
这个问题真的困扰我很久
最麻烦的莫过於当你已经malloc()了一大堆东西
却因为某个原因必须跳出来
照原先为正常情况设计的free()的顺序清掉
又可能因为前面执行不完全而造成一大堆的segfault
或是double free
真是想不透该怎麽办啊啊啊啊啊
--
The inherent vice of capitalism is the unequal sharing of blessings;
the inherent virtue of socialism is the equal sharing of misery.
-- Churchill
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.126.35.92
1F:推 yhuiyang:针对避免 double free, 一般常用 12/19 00:15
2F:→ yhuiyang:if (ptr) 12/19 00:16
3F:→ yhuiyang:{ 12/19 00:16
4F:→ yhuiyang: free(ptr); 12/19 00:16
5F:→ yhuiyang: ptr = NULL; 12/19 00:17
6F:→ yhuiyang:} 12/19 00:17
7F:→ andytzeng:参考前面的 valgrind 来 debug 试试.. 12/19 00:48
8F:推 gen2linux:linux kernel里很喜欢用goto..喜欢用就学吧 12/19 01:20
9F:推 qrtt1:改用 memory pool,或gc library 12/19 06:52
10F:推 andytzeng:kernel 用 goto 应该一部份为了 downsize 吧.. 12/19 12:35
11F:推 dozer:对耶 memory pool竟然有这种妙处 真是太强啦! 12/19 17:59