PspDereferenceQuotaBlock

VOID __stdcall PspDereferenceQuotaBlock(_EPROCESS_QUOTA_BLOCK *QuotaBlock){
  int v2; 
  char *v3; 
  _BYTE *ExpansionLink; 
  __int64 v5; 
  UINT64 v6; 
  __int64 v7; 

  if( _InterlockedExchangeAdd((volatile signed __int32 *)&QuotaBlock->ReferenceCount, 0xFFFFFFFF) == 1 )
  {
    v2 = 0;
    v3 = PspResourceFlags;
    ExpansionLink = QuotaBlock->QuotaEntry[0].ExpansionLink;
    do
    {
      if( (*v3 & 3) == 1 )
      {
        v5 = *((_QWORD *)ExpansionLink + 1);
        v6 = *((_QWORD *)ExpansionLink - 1);
        if( v6 + *(_QWORD *)ExpansionLink )
        {
          if( v5 )
          {
            v7 = _InterlockedExchange64((volatile __int64 *)ExpansionLink, 0i64);
            v6 = _InterlockedExchange64((volatile __int64 *)ExpansionLink - 1, 0i64) + v7;
          }
        }
        else
        {
          v6 = 0i64;
        }
        if( v6 || v5 )
          PspReturnResourceQuota((_PS_RESOURCE_TYPE)v2, (_PSP_QUOTA_ENTRY *)(ExpansionLink - 72), v6, v5 != 0);
      }
      ++v2;
      ExpansionLink += 128;
      v3 += 8;
    }
    while( v2 < 4 );
    PspRemoveQuotaBlock(QuotaBlock);
    ExFreePoolWithTag(QuotaBlock, 0);
  }
}

Referenced by:

ObpFreeObject
PsReturnSharedPoolQuota
PspAssignProcessQuotaBlock