+/* This file is part of centaur.
+ *
+ * centaur is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License 2 as
+ * published by the Free Software Foundation.
+
+ * centaur is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with centaur. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include <assert.h>
#include <stdlib.h>
#include <string.h>
void elfu_mPhdrDestroy(ElfuPhdr* mp)
{
- ElfuPhdr *mp2;
- ElfuScn *ms;
-
assert(mp);
- 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);
+ }
}
- CIRCLEQ_FOREACH(ms, &mp->childScnList, elemChildScn) {
- CIRCLEQ_REMOVE(&mp->childScnList, ms, elemChildScn);
- elfu_mScnDestroy(ms);
+ if (!CIRCLEQ_EMPTY(&mp->childScnList)) {
+ ElfuScn *nextms;
+
+ nextms = CIRCLEQ_FIRST(&mp->childScnList);
+ while ((void*)nextms != (void*)&mp->childScnList) {
+ ElfuScn *curms = nextms;
+ nextms = CIRCLEQ_NEXT(curms, elemChildScn);
+ CIRCLEQ_REMOVE(&mp->childScnList, curms, elemChildScn);
+ elfu_mScnDestroy(curms);
+ }
}
free(mp);