亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: 我以前對realloc的使用方式可能會造成內(nèi)存泄露 [打印本頁]

作者: heixia108    時間: 2011-03-29 16:35
標題: 我以前對realloc的使用方式可能會造成內(nèi)存泄露
  1. char *p = (char *)malloc(size);
  2. ....
  3. p = (char *)realloc(p, newsize);
復制代碼


如果realloc失敗,那么p = NULL,而此前p所指向的內(nèi)存將可能產(chǎn)生丟失(因為沒有free,而現(xiàn)在我們很可能沒有記錄p以前的值)
realloc() returns a pointer to the newly allocated memory, which is suitably aligned for any kind of variable and
       may be different from ptr, or NULL if the request fails.  If size was equal to 0, either NULL or a pointer  suit-
       able  to  be  passed  to  free() is returned.  If realloc() fails the original block is left untouched; it is not
       freed or moved.

作者: hellioncu    時間: 2011-03-29 16:52
才發(fā)現(xiàn)呀
作者: fender0107401    時間: 2011-03-29 17:46
埋地雷的。
作者: fender0107401    時間: 2011-03-29 17:47
用cscope可以很容易的找到項目里面所有realloc的調(diào)用。
作者: egmkang    時間: 2011-03-29 17:49
從來都不用realloc
作者: nizvoo    時間: 2011-03-29 18:02
還好我沒有用過。




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2