@@ -176,26 +176,29 @@ bool q_delete_dup(struct list_head *head)
176
176
if (!head || list_empty (head )) /* input validation */
177
177
return false;
178
178
179
- bool flag = false;
180
179
element_t * curr_entry = list_first_entry (head , element_t , list );
181
- element_t * next_entry ;
182
-
183
180
while (& curr_entry -> list != head ) {
184
- next_entry = list_entry (curr_entry -> list .next , element_t , list );
181
+ struct list_head * next = curr_entry -> list .next ;
182
+ element_t * next_entry = list_entry (next , element_t , list );
185
183
184
+ /* check if there is duplicate element */
185
+ bool check = false;
186
186
while (& next_entry -> list != head &&
187
187
!strcmp (curr_entry -> value , next_entry -> value )) {
188
+ struct list_head * tmp = next_entry -> list .next ;
188
189
list_del (& next_entry -> list );
189
190
q_release_element (next_entry );
190
- /* update next pointer */
191
- next_entry = list_entry (curr_entry -> list .next , element_t , list );
192
- flag = true;
191
+ next_entry = list_entry (tmp , element_t , list );
192
+ check = true;
193
193
}
194
194
195
- if (flag ) { /*need remove current node*/
195
+ if (check ) {
196
+ struct list_head * tmp = curr_entry -> list .next ;
196
197
list_del (& curr_entry -> list );
197
198
q_release_element (curr_entry );
198
- flag = false;
199
+ curr_entry = list_entry (tmp , element_t , list );
200
+ } else {
201
+ curr_entry = next_entry ;
199
202
}
200
203
}
201
204
return true;
0 commit comments