# 2021q1 Homework4 (refinement)
contributed by < `gyes00205` >
###### tags: `linux2021`
> [作業要求](https://hackmd.io/@sysprog/By7ewkAX_)
### Homework1 (quiz1): pointer to pointer 的使用時機
```cpp
static void list_free(node_t **list) {
while (*list) {
node_t *tmp = *list;
list = &((*list)->next);
free(tmp);
}
}
```
:::warning
錯誤訊息:
free(): double free detected in tcache 2
Aborted (core dumped)
> 只有在更改 linked list 的指標 (而非所指向的記憶體空間) 時,pointer to pointer 的技巧才有存在的必要,如果要釋放記憶體內容用一個 pointer 就好,解決方法如下:
:::
```cpp
static void list_free(node_t *list) {
while (list) {
node_t *tmp = list;
list = list->next;
free(tmp);
}
}
```
### 待補強作業: Homework2 (quiz2) 測驗四