Exemple #1
0
/*
 * If zero is true, zeroize the arena memory before freeing it.
 */
void
PORT_FreeArena(PLArenaPool *arena, PRBool zero)
{
    PORTArenaPool *pool = (PORTArenaPool *)arena;
    PRLock *lock = (PRLock *)0;
    size_t len = sizeof *arena;

    if (!pool)
        return;
    if (ARENAPOOL_MAGIC == pool->magic) {
        len = sizeof *pool;
        lock = pool->lock;
        PZ_Lock(lock);
    }
    if (zero) {
        PL_ClearArenaPool(arena, 0);
    }
    (void)PR_CallOnce(&setupUseFreeListOnce, &SetupUseFreeList);
    if (useFreeList) {
        PL_FreeArenaPool(arena);
    } else {
        PL_FinishArenaPool(arena);
    }
    PORT_ZFree(arena, len);
    if (lock) {
        PZ_Unlock(lock);
        PZ_DestroyLock(lock);
    }
}
Exemple #2
0
/*
 * If zero is true, zeroize the arena memory before freeing it.
 */
void
PORT_FreeArena(PLArenaPool *arena, PRBool zero)
{
    PORTArenaPool *pool = (PORTArenaPool *)arena;
    PRLock *       lock = (PRLock *)0;
    size_t         len  = sizeof *arena;
    static PRBool  checkedEnv = PR_FALSE;
    static PRBool  doFreeArenaPool = PR_FALSE;

    if (!pool)
    	return;
    if (ARENAPOOL_MAGIC == pool->magic ) {
	len  = sizeof *pool;
	lock = pool->lock;
	PZ_Lock(lock);
    }
    if (!checkedEnv) {
	/* no need for thread protection here */
	doFreeArenaPool = (PR_GetEnv("NSS_DISABLE_ARENA_FREE_LIST") == NULL);
	checkedEnv = PR_TRUE;
    }
    if (zero) {
	PL_ClearArenaPool(arena, 0);
    }
    if (doFreeArenaPool) {
	PL_FreeArenaPool(arena);
    } else {
	PL_FinishArenaPool(arena);
    }
    PORT_ZFree(arena, len);
    if (lock) {
	PZ_Unlock(lock);
	PZ_DestroyLock(lock);
    }
}
Exemple #3
0
nsPresArena::~nsPresArena()
{
#if defined(MOZ_HAVE_MEM_CHECKS)
  mFreeLists.EnumerateEntries(UnpoisonFreeList, nullptr);
#endif
  PL_FinishArenaPool(&mPool);
}
int main()
{
    while (___sl_get_nondet_int()) {
        PLArenaPool pool;

        while (___sl_get_nondet_int()) {
            // initialize arena pool
            PL_InitArenaPool(&pool, "cool pool", 0x1000, 0x10);

            torture_arena(&pool);
            ___sl_plot("01-torture_arena");

            PL_FreeArenaPool(&pool);
            ___sl_plot("02-PL_FreeArenaPool");

            PL_FinishArenaPool(&pool);
            ___sl_plot("03-PL_FinishArenaPool");
        }

        ___sl_plot("04-done");

        PL_ArenaFinish();
        ___sl_plot("05-PL_ArenaFinish");
    }

    return 0;
}
nsPersistentProperties::~nsPersistentProperties()
{
  PL_FinishArenaPool(&mArena);
  if (mTable.ops) {
    PL_DHashTableFinish(&mTable);
  }
}
/* # 509 "arena.c" */
 PRStatus
nssArena_Destroy
(
  NSSArena *arena
)
{
  PRLock *lock;







  if( (PRLock *)((void *)0) == arena->lock ) {

    nss_SetError(NSS_ERROR_INVALID_ARENA);
    return PR_FAILURE;
  }
  PR_Lock(arena->lock);
/* # 542 "arena.c" */
  PL_FinishArenaPool(&arena->pool);
  lock = arena->lock;
  arena->lock = (PRLock *)((void *)0);
  PR_Unlock(lock);
  PR_DestroyLock(lock);
  (void)nss_ZFreeIf(arena);
  return PR_SUCCESS;
}
/* Frees up all the objects except the callback list. */
void PREF_CleanupPrefs()
{
    if (gHashTable.ops) {
        PL_DHashTableFinish(&gHashTable);
        gHashTable.ops = nsnull;
        PL_FinishArenaPool(&gPrefNameArena);
    }
}
Exemple #8
0
void
PORT_DestroyCheapArena(PORTCheapArenaPool *pool)
{
    (void)PR_CallOnce(&setupUseFreeListOnce, &SetupUseFreeList);
    if (useFreeList) {
        PL_FreeArenaPool(&pool->arena);
    } else {
        PL_FinishArenaPool(&pool->arena);
    }
}
Exemple #9
0
nsDisplayListBuilder::~nsDisplayListBuilder() {
  NS_ASSERTION(mFramesMarkedForDisplay.Length() == 0,
               "All frames should have been unmarked");
  NS_ASSERTION(mPresShellStates.Length() == 0,
               "All presshells should have been exited");
  NS_ASSERTION(!mCurrentTableItem, "No table item should be active");

  PL_FreeArenaPool(&mPool);
  PL_FinishArenaPool(&mPool);
}
nsresult
nsPermissionManager::RemoveAllFromMemory()
{
  mLargestID = 0;
  mTypeArray.Clear();
  mHostTable.Clear();
  if (gHostArena) {
    PL_FinishArenaPool(gHostArena);
    delete gHostArena;
  }
  gHostArena = nsnull;
  return NS_OK;
}
Exemple #11
0
/*
 * If zero is true, zeroize the arena memory before freeing it.
 */
void
PORT_FreeArena(PLArenaPool *arena, PRBool zero)
{
    PORTArenaPool *pool = (PORTArenaPool *)arena;
    PRLock *       lock = (PRLock *)0;
    size_t         len  = sizeof *arena;
    extern const PRVersionDescription * libVersionPoint(void);
    static const PRVersionDescription * pvd;
    static PRBool  doFreeArenaPool = PR_FALSE;

    if (ARENAPOOL_MAGIC == pool->magic ) {
	len  = sizeof *pool;
	lock = pool->lock;
	PZ_Lock(lock);
    }
    if (!pvd) {
	/* Each of NSPR's DLLs has a function libVersionPoint().
	** We could do a lot of extra work to be sure we're calling the
	** one in the DLL that holds PR_FreeArenaPool, but instead we
	** rely on the fact that ALL NSPR DLLs in the same directory
	** must be from the same release, and we call which ever one we get. 
	*/
	/* no need for thread protection here */
	pvd = libVersionPoint();
	if ((pvd->vMajor > 4) || 
	    (pvd->vMajor == 4 && pvd->vMinor > 1) ||
	    (pvd->vMajor == 4 && pvd->vMinor == 1 && pvd->vPatch >= 1)) {
	    const char *ev = PR_GetEnv("NSS_DISABLE_ARENA_FREE_LIST");
	    if (!ev) doFreeArenaPool = PR_TRUE;
	}
    }
    if (zero) {
	PLArena *a;
	for (a = arena->first.next; a; a = a->next) {
	    PR_ASSERT(a->base <= a->avail && a->avail <= a->limit);
	    memset((void *)a->base, 0, a->avail - a->base);
	}
    }
    if (doFreeArenaPool) {
	PL_FreeArenaPool(arena);
    } else {
	PL_FinishArenaPool(arena);
    }
    PORT_ZFree(arena, len);
    if (lock) {
	PZ_Unlock(lock);
	PZ_DestroyLock(lock);
    }
}
Exemple #12
0
void tmreader_destroy(tmreader *tmr)
{
    if (tmr->libraries)
        PL_HashTableDestroy(tmr->libraries);
    if (tmr->filenames)
        PL_HashTableDestroy(tmr->filenames);
    if (tmr->components)
        PL_HashTableDestroy(tmr->components);
    if (tmr->methods)
        PL_HashTableDestroy(tmr->methods);
    if (tmr->callsites)
        PL_HashTableDestroy(tmr->callsites);
    PL_FinishArenaPool(&tmr->arena);
    free(tmr);
}
int main()
{
    PLArenaPool pool;
    PL_InitArenaPool(&pool, "cool pool", 0x1000, 0x10);
    ___sl_plot("PL_InitArenaPool");

    // this should be OK
    PL_FreeArenaPool(&pool);
    ___sl_plot("PL_FreeArenaPool-01");
    PL_FreeArenaPool(&pool);
    ___sl_plot("PL_FreeArenaPool-02");
    PL_FinishArenaPool(&pool);
    ___sl_plot("PL_FinishArenaPool-00");

    PL_ArenaFinish();
    return 0;
}
int main()
{
    while (___sl_get_nondet_int()) {
        PLArenaPool pool;

        while (___sl_get_nondet_int()) {
            // initialize arena pool
            PL_InitArenaPool(&pool, "cool pool", 0x1000, sizeof(double));

            torture_arena(&pool);

            PL_FreeArenaPool(&pool);
            PL_FinishArenaPool(&pool);
        }

        PL_ArenaFinish();
    }

    return 0;
}
Exemple #15
0
//---------------------------------------------
//  nsZipArchive::CloseArchive
//---------------------------------------------
nsresult nsZipArchive::CloseArchive()
{
#ifndef STANDALONE
  if (mFd) {
    PL_FinishArenaPool(&mArena);
  }

  // CAUTION:
  // We don't need to delete each of the nsZipItem as the memory for
  // the zip item and the filename it holds are both allocated from the Arena.
  // Hence, destroying the Arena is like destroying all the memory
  // for all the nsZipItem in one shot. But if the ~nsZipItem is doing
  // anything more than cleaning up memory, we should start calling it.
  // Let us also cleanup the mFiles table for re-use on the next 'open' call
  for (int i = 0; i < ZIP_TABSIZE; i++) {
    mFiles[i] = 0;
  }
#else
  // delete nsZipItems in table
  nsZipItem* pItem;
  for (int i = 0; i < ZIP_TABSIZE; ++i)
  {
    pItem = mFiles[i];
    while (pItem != 0)
    {
      mFiles[i] = pItem->next;
      free(pItem);
      pItem = mFiles[i];
    }
    mFiles[i] = 0;              // make sure we don't double-delete
  }
#endif
  
  if (mFd) {
    PR_Close(mFd);
    mFd = 0;
  }
  mBuiltSynthetics = PR_FALSE;
  return ZIP_OK;
}
Exemple #16
0
/*
** StressThread()
** A bunch of these beat on individual arenas
** This tests the free_list protection.
**
*/
static void PR_CALLBACK StressThread( void *arg )
{
    PLArenaPool ap;
    PRIntn i;
    PRIntn sz;
    void *ptr;
    PRThread *tp = PR_GetCurrentThread();

    PR_LOG( tLM, PR_LOG_DEBUG, ("Stress Thread %p started\n", PR_GetCurrentThread()));
    PL_InitArenaPool( &ap, "TheArena", RandSize( poolMin, poolMax), sizeof(double));

    for ( i = 0; i < stressIterations; i++ )
    {
        PRIntn allocated = 0;

        while ( allocated < maxAlloc )
        {
            sz = RandSize( arenaMin, arenaMax );
            PL_ARENA_ALLOCATE( ptr, &ap, sz );
            if ( ptr == NULL )
            {
                PR_LOG( tLM, PR_LOG_ERROR, ("ARENA_ALLOCATE() returned NULL\n\tAllocated: %d\n", allocated));
                break;
            }
            allocated += sz;
        }
        PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p finished one iteration\n", tp));
        PL_FreeArenaPool( &ap );
    }
    PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p finished all iteration\n", tp));
    PL_FinishArenaPool( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p after FinishArenaPool()\n", tp));

    /* That's all folks! let's quit */
    PR_EnterMonitor(tMon);
    threadCount--;
    PR_Notify(tMon);
    PR_ExitMonitor(tMon);    
    return;
}    
Exemple #17
0
/*
** Test arena Mark and Release.
*/
static void MarkAndRelease( void )
{
    PLArenaPool ap;
    void    *ptr = NULL;
    void    *mark0, *mark1;
    PRIntn  i;

    PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
    mark0 = PL_ARENA_MARK( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("mark0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m0: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark0 ));

	for( i = 0; i < 201; i++ )
	{
		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
        PR_LOG( tLM, PR_LOG_DEBUG,
            ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
                &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
	}

    mark1 = PL_ARENA_MARK( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("mark1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m1: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark1 ));


	for( i = 0; i < 225; i++ )
	{
		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
        PR_LOG( tLM, PR_LOG_DEBUG,
            ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
                &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
	}

    PL_ARENA_RELEASE( &ap, mark1 );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Release-1: %p -- Pool: %p. first: %p, current: %p, size: %d", 
               mark1, &ap, ap.first, ap.current, ap.arenasize  ));

	for( i = 0; i < 20; i++ )
	{
		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
        PR_LOG( tLM, PR_LOG_DEBUG,
            ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
                &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
	}

    PL_ARENA_RELEASE( &ap, mark1 );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Release-1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));

    PL_ARENA_RELEASE( &ap, mark0 );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Release-0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));

    PL_FreeArenaPool( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Free. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
    
    PL_FinishArenaPool( &ap );
    PR_LOG( tLM, PR_LOG_DEBUG,
        ("Finish. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));

    return;
} /* end MarkAndRelease() */
nsStringBundleService::~nsStringBundleService()
{
  flushBundleCache();
  PL_FinishArenaPool(&mCacheEntryPool);
}
 ~State()
 {
   PL_FinishArenaPool(&mPool);
 }
Exemple #20
0
void pool_destroy(pool_t *pool) {
  PL_FinishArenaPool(pool);
  free(pool);
}