I have a school project that I made in C (It's actually college level, but nvm). It is quite big and it works fine....in debug mode. When I build it however, it crashes. I managed to locate the problem and it looks like this(the names are in my native language so I changed them):
typedef struct
{
int a, b;
another_struct **another_struct_handle;
} my_struct;
void some_function(const int n, my_struct **my_struct_handle)
{
//some code
*my_struct_handle=(my_struct *)malloc(n*sizeof(my_struct)); // this is where it crashes
//some code
}
int main()
{
my_struct *my_struct_handle;
some_function(10, &my_struct_handle);
}
Few notes:
- I already do exactly the same thing with another_struct in other function and it doesn't crash. This "other function" is called before some_function, of course;
- This crashes ONLY when i build the project, not on debug;
- I compile the project with GNU GCC in code::blocks (if it have any importance);
- The compiler don't give me any warnings or errors anywhere in my code;
- I am not allowed to use global variables, that's why I need to pass a pointer to a pointer.
Any ideas? Thanks in advance.