free_LIST()
- http://www.tees.ne.jp/~sin-x/200910a.html#0901
- http://shinh.skr.jp/m/?date=20091011#p01
- http://www.tees.ne.jp/~sin-x/200910b.html#1201
- http://homepage1.nifty.com/herumi/diary/0910.html#12
ã®è©±ã
ä½ãã¹ããã®ã
ä»æ§ã®è©±ã¨ãã¦ã¯
ãªã¹ãã®å é ãä¸ããã¨ãå帰çã«ãªã¹ãæ«å°¾ãã free() ãã¦ããããããªã©ããã¼
ã¯å¿
è¦ã ã¨æãããããã¹ã¿ãã¯ãé£ãæ½°ãå®è£
ã«ãªã£ã¦ãããã¾ãåé¡ãããããã ããã©ããããã¾ã§è¦å®ãã¦ããä»æ§ã¯æ»
å¤ã«ãªãããNNNè¦ç´ ã¾ã§å¦çã§ãããã¨ãã¨è¦å®ããã¦ããã°ä¸åºæ¥ã*1ã
ä¸å¿ããã¿ã«åèµ·ãã«ã¼ãã¸å¤æããã¨ãããªæãããCè¨èªã§æ«å°¾å¼ã³åºãã®æé©åãè¦å®ããã®ã¯ãã£ããé£ãããªã
static LIST* free_LIST_first(LIST *list) { LIST* next; assert(list != NULL); next = list->next; free(list->name); free(list); return next; } void free_LIST(LIST *list) { while (list != NULL) { list = free_LIST_first(list); } }
æè²ã¨ãã¦ã¯ã
Cè¨èªã¯è¨ç®ç§å¦ã¨é¢ä¿ã®ãªãè¦ç´ ãå¤ãããããæåã«ç¿ãããã°ã©ãã³ã°è¨èªã¨ãã¦ã¯ãã¾ããå§ãã§ããªãã®ããªã¨æãããã«ãªã£ããè¨ç®*æ©*ç§å¦ã®ä¸ã®ãã¼ãã¦ã§ã¢æè²ã®ä¸ç°ã§æããã®ãªãæè¯ã®é¸æã ã¨æãã®ã¯å¤ãããªãããã©ãã
*1:æ¬å½ã¯ããã¨ããæ¡ä»¶ã§ããä»ãã¦ããªãã¨ãã¡ãªã®ã ãã©ãã