GPLv2 release
[centaur.git] / src / libelfu / model / section.c
index 74fbc3acb19ece9fc26932accb5a25b81cd8333e..3e6c89f2afc6923d3dbf88aa29c79965d6b9fe84 100644 (file)
@@ -1,3 +1,18 @@
+/* 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>
@@ -11,8 +26,6 @@ void* elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2)
   ElfuPhdr *mp;
   ElfuScn *ms;
 
-  // TODO: Sort PHDRs by offset before interating
-
   CIRCLEQ_FOREACH(mp, &me->phdrList, elem) {
     if (mp->phdr.p_type != PT_LOAD) {
       continue;
@@ -248,7 +261,29 @@ void elfu_mScnDestroy(ElfuScn* ms)
 {
   assert(ms);
 
-  // TODO: Free symtab/reltab
+  if (!CIRCLEQ_EMPTY(&ms->symtab.syms)) {
+    ElfuSym *nextsym;
+
+    nextsym = CIRCLEQ_FIRST(&ms->symtab.syms);
+    while ((void*)nextsym != (void*)&ms->symtab.syms) {
+      ElfuSym *cursym = nextsym;
+      nextsym = CIRCLEQ_NEXT(cursym, elem);
+      CIRCLEQ_REMOVE(&ms->symtab.syms, cursym, elem);
+      free(cursym);
+    }
+  }
+
+  if (!CIRCLEQ_EMPTY(&ms->reltab.rels)) {
+    ElfuRel *nextrel;
+
+    nextrel = CIRCLEQ_FIRST(&ms->reltab.rels);
+    while ((void*)nextrel != (void*)&ms->reltab.rels) {
+      ElfuRel *currel = nextrel;
+      nextrel = CIRCLEQ_NEXT(currel, elem);
+      CIRCLEQ_REMOVE(&ms->reltab.rels, currel, elem);
+      free(currel);
+    }
+  }
 
   if (ms->databuf) {
     free(ms->databuf);