Changeset 10907 for branches/jch-memory/psLib/src/sys/psMemory.c
- Timestamp:
- Jan 4, 2007, 3:56:34 PM (19 years ago)
- File:
-
- 1 edited
-
branches/jch-memory/psLib/src/sys/psMemory.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/jch-memory/psLib/src/sys/psMemory.c
r10906 r10907 9 9 * @author Joshua Hoblitt, University of Hawaii 10 10 * 11 * @version $Revision: 1.88.2.1 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-01-05 01: 15:33$11 * @version $Revision: 1.88.2.15 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-01-05 01:56:34 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 58 58 fprintf(stderr, "%s (%s:%d) ", func, filename, lineno); \ 59 59 fprintf(stderr, __VA_ARGS__);\ 60 psErrorStackPrint(stderr, "\nAborting. Error stack: "); \60 psErrorStackPrint(stderr, "\nAborting. Error stack:\n"); \ 61 61 fprintf(stderr, "\n");\ 62 62 abort(); … … 74 74 #define HANDLE_BAD_BLOCK(memBlock, file, lineo, func) \ 75 75 if (badMemBlock(stderr, memBlock, file, lineo, func)) { \ 76 psMemBlockPrint(stderr, memBlock); \ 77 PS_MEM_ABORT(__func__, "Unsafe to Continue"); \ 76 PS_MEM_ABORT(__func__, "Unsafe to Continue\n"); \ 78 77 } 79 78 … … 155 154 // p_psAlloc/p_psFree here. 156 155 157 // ->nextBlock, & -> prevousBlock should not be looked at but this function 158 // as they make be changed out from underneath us by new memory allocation 156 bool bad = false; 157 bool blockPrinted = false; 158 159 159 if (memBlock == NULL) { 160 fprintf(output, _("NULL memory block. Caught in %s at (%s:%d.)."), func, file, lineno); 160 fprintf(output, _("NULL memory block.\n" 161 "Caught in %s at (%s:%d.).\n"), func, file, lineno); 162 // return now as we can't do anything else 161 163 return true; 162 164 } 163 165 164 if (memBlock->refCounter == 0) {166 if (memBlock->refCounter < 1) { 165 167 // using an unreferenced block of memory, are you? 166 fprintf(output, _("Memory block was freed but still being used. Caught in %s at (%s:%d)."), func, file, lineno); 167 return true; 168 psMemBlockPrint(output, memBlock); 169 blockPrinted = true; 170 fprintf(output, _("\n\tMemory block was freed but still being used.\n")); 171 bad = true; 168 172 } 169 173 170 174 if (memBlock->startblock != P_PS_MEMMAGIC || memBlock->endblock != P_PS_MEMMAGIC) { 171 fprintf(output, _("Memory block is corrupted; buffer underflow detected.Caught in %s at (%s:%d)."), func, file, lineno); 172 return true; 173 } 175 if (!blockPrinted) { 176 psMemBlockPrint(output, memBlock); 177 blockPrinted = true; 178 } 179 fprintf(output, _("\n\tMemory block is corrupted; buffer underflow detected.\n")); 180 bad = true; 181 } 182 174 183 if (*(psPtr *)((int8_t *) (memBlock + 1) + memBlock->userMemorySize) != P_PS_MEMMAGIC) { 175 fprintf(output, 176 _("Memory block is corrupted; buffer overflow detected. Caught in %s at (%s:%d)."), func, file, lineno); 177 return true; 178 } 179 180 return false; 184 if (!blockPrinted) { 185 psMemBlockPrint(output, memBlock); 186 blockPrinted = true; 187 } 188 fprintf(output, _("\n\tMemory block is corrupted; buffer overflow detected.\n")); 189 bad = true; 190 } 191 192 // XXX ->nextBlock, & -> prevousBlock really should not be looked at by 193 // this function as they may be changed out from underneath us by new 194 // memory allocation. However, the memBlock itself shouldn't go away (end 195 // users responsiblity) so all we're really risking is a garbage value. 196 197 if (memBlock == memBlock->nextBlock) { 198 if (!blockPrinted) { 199 psMemBlockPrint(output, memBlock); 200 blockPrinted = true; 201 } 202 fprintf(output, _("\n\tMemory block's ->nextBlock pointer refers to itself.\n")); 203 bad = true; 204 } 205 206 if (memBlock == memBlock->previousBlock) { 207 if (!blockPrinted) { 208 psMemBlockPrint(output, memBlock); 209 blockPrinted = true; 210 } 211 fprintf(output, _("\n\tMemory block's ->previousBlock pointer refers to itself.\n")); 212 bad = true; 213 } 214 215 if (bad) { 216 fprintf(output, _("\tCaught in %s at (%s:%d).\n"), func, file, lineno); 217 } 218 219 return bad; 181 220 } 182 221 … … 323 362 if (badMemBlock(output, memBlock, __FILE__, __LINE__, __func__)) { 324 363 nbad++; 325 326 psMemBlockPrint(output, memBlock);327 364 328 365 if (abort_on_error) { … … 458 495 if (memBlock == NULL) { 459 496 MUTEX_UNLOCK(&memBlockListMutex); 497 psMemBlockPrint(stderr, ((psMemBlock *)ptr) - 1); 460 498 fprintf(stderr, "Problem reallocating block\n"); 461 psMemBlockPrint(stderr, ((psMemBlock *)ptr) - 1);462 499 PS_MEM_ABORT(__func__, "Failed to reallocate to %zd bytes at %s (%s:%d)", size, func, file, lineno); 463 500 } … … 1076 1113 { 1077 1114 return fprintf(output, 1078 "Memory Block ID: %lu \n"1115 "Memory Block ID: %lu @ %p\n" 1079 1116 "\tPrevious Block: %p Next Block: %p\n" 1080 1117 "\tFree function: %p\n" … … 1083 1120 "\tAllocated in %s at (%s:%d)\n" 1084 1121 "\t\tby Thread ID %lu\n", 1085 memBlock->id, 1122 memBlock->id, memBlock, 1086 1123 memBlock->previousBlock, memBlock->nextBlock, 1087 1124 memBlock->freeFunc, 1088 1125 memBlock->userMemorySize, memBlock->refCounter, (memBlock->persistent ? "Yes" : "No"), 1089 memBlock->startblock, memBlock->endblock, (memBlock + 1 + memBlock->userMemorySize), 1126 memBlock->startblock, memBlock->endblock, 1127 *(psPtr *)((int8_t *) (memBlock + 1) + memBlock->userMemorySize), 1090 1128 memBlock->func, memBlock->file, memBlock->lineno, memBlock->tid); 1091 1129 }
Note:
See TracChangeset
for help on using the changeset viewer.
