Implement memory management TODOs
[centaur.git] / src / libelfu / modelops / layout.c
index f8a30ed4e2d66b4a40eebbfd45fb70e77abeeb84..182ed2e4ec6d9e30339e13c4ceef0c854771a49d 100644 (file)
@@ -101,7 +101,8 @@ static ElfuPhdr* appendPhdr(ElfuElf *me)
                                 &lowestOffs, &highestOffsEnd);
     if (phdr_maxsz < (me->ehdr.e_phnum + 1) * me->ehdr.e_phentsize
         && phdrmp == lowestAddr
-        && phdrmp == lowestOffs) {
+        && phdrmp == lowestOffs
+        && (lowestAddr->phdr.p_vaddr >= 2 * lowestAddr->phdr.p_align)) {
       ElfuPhdr *mp;
       ElfuScn *ms;
       GElf_Word size = ROUNDUP(me->ehdr.e_phentsize, phdrmp->phdr.p_align);
@@ -344,7 +345,6 @@ int elfu_mLayoutAuto(ElfuElf *me)
   ElfuPhdr *highestOffsEnd;
   ElfuPhdr *mp;
   ElfuScn *ms;
-  ElfuPhdr **phdrArr;
   GElf_Off lastend = 0;
 
   assert(me);
@@ -353,12 +353,6 @@ int elfu_mLayoutAuto(ElfuElf *me)
   elfu_mPhdrLoadLowestHighest(me, &lowestAddr, &highestAddr,
                               &lowestOffs, &highestOffsEnd);
 
-  phdrArr = malloc(elfu_mPhdrCount(me) * sizeof(*phdrArr));
-  if (!phdrArr) {
-    ELFU_WARN("elfu_mLayoutAuto: malloc failed for phdrArr.\n");
-    return 1;
-  }
-
 
   lastend = OFFS_END(highestOffsEnd->phdr.p_offset, highestOffsEnd->phdr.p_filesz);