I have this problem when reallocating memory. I have created a program which you can put information about diffrent grocery items. A small scale shopping list. I'm trying to make the list of items exapnd and shrink for every new item that is put in the list. For the first item it doesnt have any sort of problem when alloctaing and freeing tha old NULL memory. But when adding more items and at the same time trying to free the allocated memory the program triggers a break point at row 144. This is the message I get. "wntdll.pdb contains the debug information required to find the source for the module ntdll.dll" What am I doing wrong?

This is the function that I have created for the purpose.

```
void addSpace(struct GroceryItem** pitemList, int listLength)
{
    int add = listLength + 1;
    struct GroceryItem * temp;
    temp = NULL;
    do {
        temp = (struct GroceryItem*)realloc(*pitemList, add * sizeof(struct GroceryItem));

    } while (temp == NULL);
    if(listLength!=0)
        free(*pitemList);
    _CrtDumpMemoryLeaks();//Cheking for memory leaks
    *pitemList = temp;
    return;
}

```

I'm very new to programmaing so if there is any problems understanding my question report it and I will try to be more specific.