C Delete Linked List By Reference? : <p>Brand new to C, tried other SO Answers that I found about this before posting, and saw that none of them were using a function and passing their list in by reference for deleting all item, but that is the way I want to implement it.  Console is outputting </p>

<blockquote>
  <p><strong>* Error in `./testing': double free or corruption (out): 0x00007ffc26622b30 *</strong> Aborted</p>
</blockquote>

<p>Awesome error message for a noob! That isn't cryptic at all. :)<br>
P.S. All of my other functions are working as intended.</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdbool.h&gt;

typedef struct node
{
    int n;
    struct node* next;
} 
node;

bool search(int number, node* list);
void showItems(node* list);
void insertItem(int number, node** list);
void deleteItem(int number, node** list);
void deleteList(node** list);

int main(void)
{

    node* list = NULL;

    insertItem(1337, &amp;list);
    insertItem(1337, &amp;list);

    bool found = search(5, list);
    if (found)
    {
        printf("found number in linked list.");
    }

    deleteList(&amp;list);

    showItems(list);
}

void showItems(node* list)
{
    node* ptr = list;
    while (ptr)
    {
        printf("%i\n",ptr-&gt;n);
        ptr = ptr-&gt;next;
    }
}

bool search(int number, node* list)
{
    node* ptr = list;
    while (ptr)
    {
        if (ptr-&gt;n == number)
        {
            return true;
        }
        ptr = ptr-&gt;next;

    }
    //Number not found.
    return false;
}

void insertItem(int number, node** list)
{
    node* newItem = malloc(sizeof(node));
    newItem-&gt;n = number;
    newItem-&gt;next = *list;
    *list = newItem;
}

void deleteItem(int number, node** list)
{

    node* ptr = *list;
    node* prev = NULL;

    while (ptr)
    {
        if (ptr-&gt;n == number)
        {
            if (prev != NULL)
            {
                //Check if there is a previous node.  If there is, set its next node to the current items next node.  Then free the current node.
                prev-&gt;next = ptr-&gt;next;

            }
            free(ptr);
            break;
        }
        prev = ptr;
        ptr = ptr-&gt;next;
    }
}

void deleteList(node** list)
{
    node* temp = NULL;
    while (list)
    {
        temp = *list;
        free(list);
        list = &amp;temp-&gt;next;
    }
}
</code></pre>
