File: _lstFreeItem.c

package info (click to toggle)
unixodbc 2.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,524 kB
  • ctags: 7,656
  • sloc: ansic: 89,405; sh: 15,975; makefile: 1,574; yacc: 969; sql: 1
file content (83 lines) | stat: -rw-r--r-- 1,690 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <config.h>
#include "lst.h"

/***************************
 * _lstFreeItem
 *
 * 1. FREES MEMORY USED BY THE LIST ITEM AND REMOVES IT FROM ITS LIST
 * 2. WILL CLEAN UP root ITEM IF REQUIRED.. NEVER SETS bDelete... lstDelete DOES SET bDelete
 * 3. CALLS _lstAdjustCurrent TO ENSURE THAT CURRENT DOES NOT END UP ON  bDelete ITEM
 ***************************/
int _lstFreeItem( HLSTITEM hItem )
{
    HLST 		hLst;
	HLSTITEM	hItemRoot;
	HLSTITEM	hNewCurrent = NULL;

    if ( !hItem )
        return LST_ERROR;

	hLst = (HLST)hItem->hLst;

	/*************
	 * FREE root ITEM AS REQUIRED
	 *************/
	if ( hLst->hLstBase )
	{
		hItemRoot = (HLSTITEM)hItem->pData;

		/*************
		 * dec ref count in root item
		 *************/
        hItemRoot->nRefs--;

		/*************
		 * DELETE root ITEM IF REF = 0 AND SOMEONE SAID DELETE IT
		 *************/
		if ( hItemRoot->nRefs < 1 && hItemRoot->bDelete )
		{
			_lstFreeItem( hItemRoot );
		}
	}

	/*************
	 * WE ALWAYS FREE hItem
	 *************/
	if ( hItem->pData && hLst->pFree )
		hLst->pFree( hItem->pData );

	if ( !hItem->bDelete )				/* THIS IS REALLY ONLY A FACTOR FOR ROOT ITEMS */
		hLst->nItems--;
	
	if ( hItem == hLst->hFirst )
		hLst->hFirst = hItem->pNext;	

	if ( hItem == hLst->hLast )
		hLst->hLast = hItem->pPrev;	

	if ( hItem->pPrev )
	{
		hItem->pPrev->pNext = hItem->pNext;	
		if ( hItem == hLst->hCurrent )
			hNewCurrent = hItem->pPrev;
	}

	if ( hItem->pNext )
	{
		hItem->pNext->pPrev = hItem->pPrev;	
		if ( !hNewCurrent && hItem == hLst->hCurrent )
			hNewCurrent = hItem->pNext;
	}

	free( hItem );

	hLst->hCurrent = hNewCurrent;

	_lstAdjustCurrent( hLst );	
	

	return LST_SUCCESS;
}