src/queue.c
void
lqueueDestroy(L_QUEUE  **plq,
              l_int32    freeflag)
{
void     *item;
L_QUEUE  *lq;

    PROCNAME("lqueueDestroy");

    if (plq == NULL) {
        L_WARNING("ptr address is NULL", procName);
        return;
    }
    if ((lq = *plq) == NULL)
        return;

    if (freeflag) {
        while(lq->nelem > 0) {
            item = lqueueRemove(lq);
            FREE(item);
        }
    }
    else if (lq->nelem > 0)
        L_WARNING_INT("memory leak of %d items in lqueue!",
                      procName, lq->nelem);

    if (lq->array)
        FREE(lq->array);
    if (lq->stack)
        lstackDestroy(&lq->stack, freeflag);
    FREE(lq);
    *plq = NULL;

    return;
}
/*!
 *  lqueueDestroy()
 *
 *      Input:  &lqueue  (<to be nulled>)
 *              freeflag (TRUE to free each remaining struct in the array)
 *      Return: void
 *
 *  Notes:
 *      (1) If freeflag is TRUE, frees each struct in the array.
 *      (2) If freeflag is FALSE but there are elements on the array,
 *          gives a warning and destroys the array.  This will
 *          cause a memory leak of all the items that were on the queue.
 *          So if the items require their own destroy function, they
 *          must be destroyed before the queue.  The same applies to the
 *          auxiliary stack, if it is used.
 *      (3) To destroy the L_Queue, we destroy the ptr array, then
 *          the lqueue, and then null the contents of the input ptr.
 */
lqueueDestroy()
Input:  &lqueue  ()
freeflag (TRUE to free each remaining struct in the array)
Return: void

(1) If freeflag is TRUE, frees each struct in the array.
(2) If freeflag is FALSE but there are elements on the array,
gives a warning and destroys the array.  This will
cause a memory leak of all the items that were on the queue.
So if the items require their own destroy function, they
must be destroyed before the queue.  The same applies to the
auxiliary stack, if it is used.
(3) To destroy the L_Queue, we destroy the ptr array, then
the lqueue, and then null the contents of the input ptr.
lqueueDestroy () Input : &lqueue () freeflag ( TRUE to free each remaining struct in the array ) Return : void ( 1 ) If freeflag is TRUE frees each struct in the array . ( 2 ) If freeflag is FALSE but there are elements on the array gives a warning and destroys the array . This will cause a memory leak of all the items that were on the queue . So if the items require their own destroy function they must be destroyed before the queue . The same applies to the auxiliary stack if it is used . ( 3 ) To destroy the L_Queue we destroy the ptr array then the lqueue and then null the contents of the input ptr .
void
lqueueDestroy(L_QUEUE  **plq,
              l_int32    freeflag)
{
void     *item;
L_QUEUE  *lq;
    PROCNAME("lqueueDestroy");
    if (plq == NULL) {
        L_WARNING("ptr address is NULL", procName);
        return;
    }
    if ((lq = *plq) == NULL)
        return;
    if (freeflag) {
        while(lq->nelem > 0) {
            item = lqueueRemove(lq);
            FREE(item);
        }
    }
    else if (lq->nelem > 0)
        L_WARNING_INT("memory leak of %d items in lqueue!",
                      procName, lq->nelem);
    if (lq->array)
        FREE(lq->array);
    if (lq->stack)
        lstackDestroy(&lq->stack, freeflag);
    FREE(lq);
    *plq = NULL;
    return;
}
void lqueueDestroy ( L_QUEUE * * plq , l_int32 freeflag ) { void * item ; L_QUEUE * lq ; PROCNAME ( " " ) ; if ( plq == NULL ) { L_WARNING ( " " , procName ) ; return ; } if ( ( lq = * plq ) == NULL ) return ; if ( freeflag ) { while ( lq -> nelem > 0 ) { item = lqueueRemove ( lq ) ; FREE ( item ) ; } } else if ( lq -> nelem > 0 ) L_WARNING_INT ( " " , procName , lq -> nelem ) ; if ( lq -> array ) FREE ( lq -> array ) ; if ( lq -> stack ) lstackDestroy ( & lq -> stack , freeflag ) ; FREE ( lq ) ; * plq = NULL ; return ; }
lqueueDestroy()
      Input:  &lqueue  (<to be nulled>)
              freeflag (TRUE to free each remaining struct in the array)
      Return: void
lqueueDestroy () Input : &lqueue ( <to be nulled > ) freeflag ( TRUE to free each remaining struct in the array ) Return : void