Пример #1
0
/*-
 *-----------------------------------------------------------------------
 * Lst_Destroy --
 *	Destroy a list and free all its resources. If the freeProc is
 *	given, it is called with the datum from each node in turn before
 *	the node is freed.
 *
 * Results:
 *	None.
 *
 * Side Effects:
 *	The given list is freed in its entirety.
 *
 *-----------------------------------------------------------------------
 */
void
Lst_Destroy(Lst list, FreeProc *freeProc)
{
    ListNode	ln;
    ListNode	tln = NULL;

    if (list == NULL)
	return;

    /* To ease scanning */
    if (list->lastPtr != NULL)
	list->lastPtr->nextPtr = NULL;
    else {
	free(list);
	return;
    }

    if (freeProc) {
	for (ln = list->firstPtr; ln != NULL; ln = tln) {
	     tln = ln->nextPtr;
	     freeProc(ln->datum);
	     free(ln);
	}
    } else {
	for (ln = list->firstPtr; ln != NULL; ln = tln) {
	     tln = ln->nextPtr;
	     free(ln);
	}
    }

    free(list);
}
Пример #2
0
void listRelease(list* l, freeValueProc* freeProc) {
    if (NULL == l) return;
    listNode *p = l->head, *next = NULL;
    while (p) {
        next = p->next;
        if (freeProc) freeProc(p->value);
        free(p);
        p = next;
    }
    free(l);
    l = NULL;
}
Пример #3
0
void free_Procs(){
  int i;
  for( i= 0; i <P1_MAXPROC; i++){
    if(procTable[i].state == 3 && procTable[i].notFreed) {
      freeProc(i);
      if(procTable[i].isOrphan){
        removeProc(i);
      }
      //USLOSS_Console("Freed %s\n",procTable[i].name);
    }
  }
}
Пример #4
0
/*-
 *-----------------------------------------------------------------------
 * Lst_Destroy --
 *	Destroy a list and free all its resources. If the freeProc is
 *	given, it is called with the datum from each node in turn before
 *	the node is freed.
 *
 * Results:
 *	None.
 *
 * Side Effects:
 *	The given list is freed in its entirety.
 *
 *-----------------------------------------------------------------------
 */
void
Lst_Destroy(Lst l, FreeProc *freeProc)
{
    ListNode	ln;
    ListNode	tln = NilListNode;
    List 	list = l;

    if (l == NILLST || ! l) {
	/*
	 * Note the check for l == (Lst)0 to catch uninitialized static Lst's.
	 * Gross, but useful.
	 */
	return;
    }

    /* To ease scanning */
    if (list->lastPtr != NilListNode)
	list->lastPtr->nextPtr = NilListNode;
    else {
	free(l);
	return;
    }

    if (freeProc) {
	for (ln = list->firstPtr; ln != NilListNode; ln = tln) {
	     tln = ln->nextPtr;
	     freeProc(ln->datum);
	     free(ln);
	}
    } else {
	for (ln = list->firstPtr; ln != NilListNode; ln = tln) {
	     tln = ln->nextPtr;
	     free(ln);
	}
    }

    free(l);
}
Пример #5
0
void
Tcl_EventuallyFree(
    ClientData clientData,	/* Pointer to malloc'ed block of memory. */
    Tcl_FreeProc *freeProc)	/* Function to actually do free. */
{
    Reference *refPtr;
    int i;

    /*
     * See if there is a reference for this pointer. If so, set its "mustFree"
     * flag (the flag had better not be set already!).
     */

    Tcl_MutexLock(&preserveMutex);
    for (i = 0, refPtr = refArray; i < inUse; i++, refPtr++) {
	if (refPtr->clientData != clientData) {
	    continue;
	}
	if (refPtr->mustFree) {
	    Tcl_Panic("Tcl_EventuallyFree called twice for 0x%x", clientData);
	}
	refPtr->mustFree = 1;
	refPtr->freeProc = freeProc;
	Tcl_MutexUnlock(&preserveMutex);
	return;
    }
    Tcl_MutexUnlock(&preserveMutex);

    /*
     * No reference for this block.  Free it now.
     */

    if (freeProc == TCL_DYNAMIC) {
	ckfree((char *) clientData);
    } else {
	freeProc((char *)clientData);
    }
}