- CIRCLEQ_FOREACH(mp2, &mp->childPhdrList, elemChildPhdr) {
- CIRCLEQ_REMOVE(&mp->childPhdrList, mp2, elemChildPhdr);
- elfu_mPhdrDestroy(mp2);
+ if (!CIRCLEQ_EMPTY(&mp->childPhdrList)) {
+ ElfuPhdr *nextmp;
+
+ nextmp = CIRCLEQ_FIRST(&mp->childPhdrList);
+ while ((void*)nextmp != (void*)&mp->childPhdrList) {
+ ElfuPhdr *curmp = nextmp;
+ nextmp = CIRCLEQ_NEXT(curmp, elemChildPhdr);
+ CIRCLEQ_REMOVE(&mp->childPhdrList, curmp, elemChildPhdr);
+ elfu_mPhdrDestroy(curmp);
+ }