I am writing some code that uses a function twice in order to create two matrices, each stored under a different variable name. However, when I try to use the function the second time, I get a segmentation fault. If I remove the first time the function is used, however, the code works fine. What can be wrong?

The way I am approaching this is by using a structure and a double pointer for each variable. I am allocating memory for each double pointer and (one at a time) sending it to the second function. That function sends my pointer to another function and returns the new values stored in the double pointer to the original function. I tried using a pointer to my double pointer and reallocating memory in the second function as well as messing with how the pointer is being sent, but nothing is working. What could be a reason that the fault occurs only if the function is used twice?

I can post code if the question can't be answered without it...