看板 LinuxDev 關於我們 聯絡資訊
這個問題真的困擾我很久 最麻煩的莫過於當你已經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
yhuiyang:針對避免 double free, 一般常用 12/19 00:15
yhuiyang:if (ptr) 12/19 00:16
yhuiyang:{ 12/19 00:16
yhuiyang: free(ptr); 12/19 00:16
yhuiyang: ptr = NULL; 12/19 00:17
yhuiyang:} 12/19 00:17
andytzeng:參考前面的 valgrind 來 debug 試試.. 12/19 00:48
gen2linux:linux kernel裡很喜歡用goto..喜歡用就學吧 12/19 01:20
qrtt1:改用 memory pool,或gc library 12/19 06:52
andytzeng:kernel 用 goto 應該一部份為了 downsize 吧.. 12/19 12:35
dozer:對耶 memory pool竟然有這種妙處 真是太強啦! 12/19 17:59