Changeset 39415
- Timestamp:
- Feb 28, 2016, 5:44:25 AM (10 years ago)
- Location:
- branches/eam_branches/ohana.20160226/src/libohana
- Files:
-
- 2 edited
-
include/ohana_allocate.h (modified) (1 diff)
-
src/ohana_allocate.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20160226/src/libohana/include/ohana_allocate.h
r39324 r39415 13 13 int line; // line (re)allocated 14 14 int freed; // memory has been freed 15 int dummy; // need to put endblock on the endpost15 int Nalloc; // need to put endblock on the endpost 16 16 uint32_t endblock; // endpost marker 17 17 } OhanaMemblock; -
branches/eam_branches/ohana.20160226/src/libohana/src/ohana_allocate.c
r39409 r39415 55 55 Nelem = MAX (1, Nelem); 56 56 size = Nelem * esize; 57 // if (size % 8) size += (8 - size % 8); // do NOT round to 8-byte boundary (did not fix corruption) 57 58 58 59 // total size is : memblock + data + endpost … … 75 76 new->func = func; 76 77 new->freed = FALSE; 78 new->Nalloc = 1; 77 79 78 80 // poison the whole memory: we should not rely of 0'ed memory … … 129 131 Nelem = MAX (1, Nelem); 130 132 size = Nelem * esize; 133 // if (size % 8) size += (8 - size % 8); // do NOT round to 8-byte boundary (did not fix corruption) 131 134 132 135 // requested same size as current allocation … … 134 137 return in; 135 138 } 139 size_t oldsize = old->size; 136 140 137 141 pthread_mutex_lock(&memBlockListMutex); … … 156 160 new->nextBlock = old->nextBlock; 157 161 new->prevBlock = old->prevBlock; 162 new->startblock = OHANA_MEMMAGIC; 163 new->endblock = OHANA_MEMMAGIC; 164 new->freed = FALSE; 158 165 # else 159 166 // ask for new memory … … 164 171 # endif 165 172 166 // set the end-post values 167 new->startblock = OHANA_MEMMAGIC; 168 new->endblock = OHANA_MEMMAGIC; 169 *(uint32_t *)(ptr_new + size) = OHANA_MEMMAGIC; 173 if (new->startblock != OHANA_MEMMAGIC) ohana_memabort ("corrupt memory (%s, %d, %s)\n", file, line, func); 174 if (new->endblock != OHANA_MEMMAGIC) ohana_memabort ("corrupt memory (%s, %d, %s)\n", file, line, func); 170 175 171 176 // set the memory metadata … … 174 179 new->line = line; 175 180 new->func = func; 176 new-> freed = FALSE;177 178 // update the endpost (the others were set originally 181 new->Nalloc++; 182 183 // update the endpost (the others were set originally and maintained through the realloc) 179 184 *(uint32_t *)(ptr_new + size) = OHANA_MEMMAGIC; 185 186 // poison the new memory: we should not rely of 0'ed memory 187 if (new->size > oldsize) { 188 memset (&ptr_new[oldsize], 0x7f, new->size - oldsize); 189 } 180 190 181 191 // need to reset lastBlock in case we moved
Note:
See TracChangeset
for help on using the changeset viewer.
