src/ptra.c
void
ptraDestroy(L_PTRA  **ppa,
            l_int32   freeflag,
            l_int32   warnflag)
{
l_int32  i, nactual;
void    *item;
L_PTRA  *pa;

    PROCNAME("ptraDestroy");

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

    ptraGetActualCount(pa, &nactual);
    if (nactual > 0) {
        if (freeflag) {
            for (i = 0; i <= pa->imax; i++) {
                if ((item = ptraRemove(pa, i, L_NO_COMPACTION)) != NULL)
                    FREE(item);
            }
        }
        else if (warnflag)
            L_WARNING_INT("potential memory leak of %d items in ptra",
                          procName, nactual);
    }

    FREE(pa->array);
    FREE(pa);
    *ppa = NULL;
    return;
}
/*!
 *  ptraDestroy()
 *
 *      Input:  &ptra (<to be nulled>)
 *              freeflag (TRUE to free each remaining item in the array)
 *              warnflag (TRUE to warn if any remaining items are not destroyed)
 *      Return: void
 *
 *  Notes:
 *      (1) If @freeflag == TRUE, frees each item in the array.
 *      (2) If @freeflag == FALSE and warnflag == TRUE, and there are
 *          items on the array, this gives a warning and destroys the array.
 *          If these items are not owned elsewhere, this will cause
 *          a memory leak of all the items that were on the array.
 *          So if the items are not owned elsewhere and require their
 *          own destroy function, they must be destroyed before the ptra.
 *      (3) If warnflag == FALSE, no warnings will be issued.  This is
 *          useful if the items are owned elsewhere, such as a
 *          PixMemoryStore().
 *      (4) To destroy the ptra, we destroy the ptr array, then
 *          the ptra, and then null the contents of the input ptr.
 */
ptraDestroy()
Input:  &ptra ()
freeflag (TRUE to free each remaining item in the array)
warnflag (TRUE to warn if any remaining items are not destroyed)
Return: void

(1) If @freeflag == TRUE, frees each item in the array.
(2) If @freeflag == FALSE and warnflag == TRUE, and there are
items on the array, this gives a warning and destroys the array.
If these items are not owned elsewhere, this will cause
a memory leak of all the items that were on the array.
So if the items are not owned elsewhere and require their
own destroy function, they must be destroyed before the ptra.
(3) If warnflag == FALSE, no warnings will be issued.  This is
useful if the items are owned elsewhere, such as a
PixMemoryStore().
(4) To destroy the ptra, we destroy the ptr array, then
the ptra, and then null the contents of the input ptr.
ptraDestroy () Input : &ptra () freeflag ( TRUE to free each remaining item in the array ) warnflag ( TRUE to warn if any remaining items are not destroyed ) Return : void ( 1 ) If @freeflag == TRUE frees each item in the array . ( 2 ) If @freeflag == FALSE and warnflag == TRUE and there are items on the array this gives a warning and destroys the array . If these items are not owned elsewhere this will cause a memory leak of all the items that were on the array . So if the items are not owned elsewhere and require their own destroy function they must be destroyed before the ptra . ( 3 ) If warnflag == FALSE no warnings will be issued . This is useful if the items are owned elsewhere such as a PixMemoryStore () . ( 4 ) To destroy the ptra we destroy the ptr array then the ptra and then null the contents of the input ptr .
void
ptraDestroy(L_PTRA  **ppa,
            l_int32   freeflag,
            l_int32   warnflag)
{
l_int32  i, nactual;
void    *item;
L_PTRA  *pa;
    PROCNAME("ptraDestroy");
    if (ppa == NULL) {
        L_WARNING("ptr address is NULL", procName);
        return;
    }
    if ((pa = *ppa) == NULL)
        return;
    ptraGetActualCount(pa, &nactual);
    if (nactual > 0) {
        if (freeflag) {
            for (i = 0; i <= pa->imax; i++) {
                if ((item = ptraRemove(pa, i, L_NO_COMPACTION)) != NULL)
                    FREE(item);
            }
        }
        else if (warnflag)
            L_WARNING_INT("potential memory leak of %d items in ptra",
                          procName, nactual);
    }
    FREE(pa->array);
    FREE(pa);
    *ppa = NULL;
    return;
}
void ptraDestroy ( L_PTRA * * ppa , l_int32 freeflag , l_int32 warnflag ) { l_int32 i , nactual ; void * item ; L_PTRA * pa ; PROCNAME ( " " ) ; if ( ppa == NULL ) { L_WARNING ( " " , procName ) ; return ; } if ( ( pa = * ppa ) == NULL ) return ; ptraGetActualCount ( pa , & nactual ) ; if ( nactual > 0 ) { if ( freeflag ) { for ( i = 0 ; i <= pa -> imax ; i ++ ) { if ( ( item = ptraRemove ( pa , i , L_NO_COMPACTION ) ) != NULL ) FREE ( item ) ; } } else if ( warnflag ) L_WARNING_INT ( " " , procName , nactual ) ; } FREE ( pa -> array ) ; FREE ( pa ) ; * ppa = NULL ; return ; }
ptraDestroy()
      Input:  &ptra (<to be nulled>)
              freeflag (TRUE to free each remaining item in the array)
              warnflag (TRUE to warn if any remaining items are not destroyed)
      Return: void
ptraDestroy () Input : &ptra ( <to be nulled > ) freeflag ( TRUE to free each remaining item in the array ) warnflag ( TRUE to warn if any remaining items are not destroyed ) Return : void