I have buggy behaviour in C++ code that seems to be caused by the incorrect freeing of dynamically created structs. The structs are in the form:
typedef struct
{
    char *value;
} Element;
typedef struct
{
    int num;
    Element **elements;
    int *index;
} Container;
They are created like this:
Element *new_element(int size)
{
    Element *elem = new Element;
    elem->value = new char[size];
    return elem;
}
Container *new_container(int num)
{
    Container *cont = new Container;
    cont->num = num;
    cont->elements = new Element*[num];
    cont->index = new int[num];
}
What is the correct way to free these?
 
     
    