MCPcopy Create free account
hub / github.com/cuberite/cuberite / Remove

Method Remove

src/LeakFinder.cpp:500–543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

498 } // Insert
499
500 BOOL Remove(HASHTABLE_KEY &key)
501 {
502 SIZE_T HashIdx;
503 AllocHashEntryType *pHashEntry, *pHashEntryLast;
504
505 // get the Hash-Value
506 HashIdx = HashFunction(key);
507
508 pHashEntryLast = NULL;
509 pHashEntry = &pAllocHashTable[HashIdx];
510 while(pHashEntry != NULL) {
511 if (pHashEntry->key == key) {
512 // release my memory
513 if (pHashEntryLast == NULL) {
514 // It is an entry in the table, so do not release this memory
515 if (pHashEntry->Next == NULL) {
516 // It was the last entry, so empty the table entry
517 SetEmptyKey(pAllocHashTable[HashIdx].key);
518 //memset(&pAllocHashTable[HashIdx], 0, sizeof(pAllocHashTable[HashIdx]));
519 }
520 else {
521 // There are some more entries, so shorten the list
522 AllocHashEntryType *pTmp = pHashEntry->Next;
523 *pHashEntry = *(pHashEntry->Next);
524 own_free(pTmp);
525 g_CurrentMemUsage -= CRTTable::AllocHashEntryTypeSize;
526 }
527 return TRUE;
528 }
529 else {
530 // now, I am in an dynamic allocated entry (it was a collision)
531 pHashEntryLast->Next = pHashEntry->Next;
532 own_free(pHashEntry);
533 g_CurrentMemUsage -= CRTTable::AllocHashEntryTypeSize;
534 return TRUE;
535 }
536 }
537 pHashEntryLast = pHashEntry;
538 pHashEntry = pHashEntry->Next;
539 }
540
541 // if we are here, we could not find the RequestID
542 return FALSE;
543 }
544
545 AllocHashEntryType *Find(HASHTABLE_KEY &key)
546 {

Callers 1

MyAllocHookFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected