Cleaner ElfuPhdr alloc
[centaur.git] / src / libelfu / model / phdr.c
index d26eb772a3c5f1c10fe037f46ce160d2faaa29fe..ce395ec2b5e78999ec76040e126a4b9dd42f72db 100644 (file)
@@ -1,4 +1,6 @@
 #include <assert.h>
+#include <stdlib.h>
+#include <string.h>
 #include <libelfu/libelfu.h>
 
 
@@ -34,3 +36,27 @@ void elfu_mPhdrUpdateChildOffsets(ElfuPhdr *mp)
     ms->shdr.sh_offset = mp->phdr.p_offset + (ms->shdr.sh_addr - mp->phdr.p_vaddr);
   }
 }
+
+
+
+/*
+ * Allocation, destruction
+ */
+
+ElfuPhdr* elfu_mPhdrAlloc()
+{
+  ElfuPhdr *mp;
+
+  mp = malloc(sizeof(ElfuPhdr));
+  if (!mp) {
+    ELFU_WARN("mPhdrAlloc: malloc() failed for ElfuPhdr.\n");
+    return NULL;
+  }
+
+  memset(mp, 0, sizeof(*mp));
+
+  CIRCLEQ_INIT(&mp->childScnList);
+  CIRCLEQ_INIT(&mp->childPhdrList);
+
+  return mp;
+}