This is not my exact code, but it is like this in essence. I'm trying to create a stack variable in main()
int **x;
that I want to pass to a function foo(int **x, arg1, arg2, ...). On some condition, I'm supposed to dynamically allocate space for x in foo()
x = (int **) malloc(sizeof(int *) * num_elems);
I am also not allocating new space for each int * element, but assigning to it &y, where int y was created in foo().
I got this error when I tried freeing x in main(). I don't understand what it means, but I suspect it might be because I used &y?
EDIT: Also relevant: I got garbage values when I tried accessing the double-dereferenced elements of x.