e2c0462cdb470785f67aaa8a4f5209ea47eb307b galt Mon Jul 1 13:48:00 2013 -0700 fixing bug in unlocking. There were too many places where returns and errAbort were leaving the routine without unlocking. It was easy to fix. Now I understand that if the user does not call pushCarefulMemHandler, then carefulParent is NULL and carefulCheckHeap exits early without doing anything. So only for routines that did NOT call pushCarefulMemHandler, but did call carefulCheckHeap multiple times was there a problem, and only pslReps util met those criteria diff --git src/lib/memalloc.c src/lib/memalloc.c index f233819..2011c27 100644 --- src/lib/memalloc.c +++ src/lib/memalloc.c @@ -344,54 +344,70 @@ unsigned char* newBlk = carefulAlloc(size); if (vpt != NULL) { struct carefulMemBlock *cmb = ((struct carefulMemBlock *)vpt)-1; memcpy(newBlk, vpt, cmb->size); carefulFree(vpt); } return newBlk; } void carefulCheckHeap() /* Walk through allocated memory and make sure that all cookies are * in place. */ { -pthread_mutex_lock( &carefulMutex ); int maxPieces = 10000000; /* Assume no more than this many pieces allocated. */ struct carefulMemBlock *cmb; char *pEndCookie; size_t size; +char errMsg[1024]; +boolean errFound = FALSE; if (carefulParent == NULL) return; +pthread_mutex_lock( &carefulMutex ); for (cmb = (struct carefulMemBlock *)(cmbAllocedList->head); cmb->next != NULL; cmb = cmb->next) { size = cmb->size; pEndCookie = (((char *)(cmb+1)) + size); if (cmb->startCookie != cmbStartCookie) - errAbort("Bad start cookie %x checking %llx\n", cmb->startCookie, + { + safef(errMsg, sizeof errMsg, "Bad start cookie %x checking %llx\n", cmb->startCookie, ptrToLL(cmb+1)); + errFound = TRUE; + break; + } if (memcmp(pEndCookie, cmbEndCookie, sizeof(cmbEndCookie)) != 0) - errAbort("Bad end cookie %x%x%x%x checking %llx\n", + { + safef(errMsg, sizeof errMsg, "Bad end cookie %x%x%x%x checking %llx\n", pEndCookie[0], pEndCookie[1], pEndCookie[2], pEndCookie[3], ptrToLL(cmb+1)); + errFound = TRUE; + break; + } if (--maxPieces == 0) - errAbort("Loop or more than 10000000 pieces in memory list"); + { + safef(errMsg, sizeof errMsg, "Loop or more than 10000000 pieces in memory list"); + errFound = TRUE; + break; + } } pthread_mutex_unlock( &carefulMutex ); +if (errFound) + errAbort("%s", errMsg); } int carefulCountBlocksAllocated() /* How many memory items are allocated? */ { pthread_mutex_lock( &carefulMutex ); int result = dlCount(cmbAllocedList); pthread_mutex_unlock( &carefulMutex ); return result; } size_t carefulTotalAllocated() /* Return total bases allocated */ { pthread_mutex_lock( &carefulMutex );