Example #1
0
/* this takes any list, and frees all of the list element, 
	and can also free the elements that they point to */
int CList_emptyList(CListHandle *list, int freeDevices, void (*free_fptr)(void *element))
{
	CListHandle last = 0, traverse = 0;

	TESTPTR(list)

	last = 0;
	for(traverse = *list; traverse; last = traverse, traverse = traverse->next)
	{
		if(traverse->element && freeDevices)
		{
			free_fptr(traverse->element);
			traverse->element = 0;
		}
		if(last)
		{
			free(last); last = NULL;
		}
	}
	if(last)
	{
		free(last); last = NULL;
	}

	*list = 0;

	return EPHIDGET_OK;
}
Example #2
0
/* this returns success even if the element is not found in the list
 * this also removes duplicates.
 */
int CList_removeFromList(CListHandle *list, void *element, 
	int (*compare_fptr)(void *element1, void *element2),
	int freeDevice, void (*free_fptr)(void *element))
{
	CListHandle traverse = 0, last = 0;

	TESTPTRS(list, element)

	for (traverse=*list; traverse; traverse = traverse->next) {
		if(compare_fptr(element, traverse->element)) {
			if(traverse == *list) {
				*list = traverse->next;
				if(freeDevice && traverse->element)
				{
					free_fptr(traverse->element);
					traverse->element = 0;
				}
				free(traverse); traverse = NULL;
				traverse=*list;
				break;
			}
			else {
				last->next=traverse->next;
				if(freeDevice && traverse->element)
				{
					free_fptr(traverse->element);
					traverse->element = 0;
				}
				free(traverse); traverse = NULL;
				traverse=last;
			}
		}
		last = traverse;
	}

	return EPHIDGET_OK;
}
Example #3
0
/* free all memory associated with list */
    void
list_free(list_t * list, void (*free_fptr)(set_t*))
{
    lnode_t *current, *next;
    assert(list != NULL);

    current = list->head;
    while(current != NULL){
        next = current->next;
        free_fptr((set_t*)current->data);
        free(current);
        current = next;
    }
    free(list);
}
void cpputest_free_location_with_leak_detection(void* buffer, const char* file, int line)
{
	free_fptr(buffer, file, line);
}