Hey,
first of all, i am writing my Code in C not, C++. I hope you could help me though.
As the title says i've got an Problem after allocating memory for an array. Allocating memory for the first array wiorks pretty fine, but after allocating memory for my second array, i can't access anymore on my first array.
I summarized my code a bit, hope i didn't neglect any important part.
int* pressureentries;
double* outputs;
void analyze_trans_file(constchar* filename)
{
if (pressureentries != NULL)
{
free(pressureentries);
pressureentries = NULL;
}
if ((pressureentries = (int*) calloc(30, sizeof(int))) == NULL)
FAIL_WITH_ERROR_CONFIG("Not enough memory");
//Working with pressureentries, works pretty fine
}
void read_trans_file(int id)
{
//access on pressureentries still works
if (outputs != NULL)
{
free(outputs);
outputs = NULL;
}
if ((outputs = (double*) calloc(23, sizeof(double))) == NULL)
FAIL_WITH_ERROR_CONFIG("not enough memory");
//access on pressurentries throws segmentation fault
}
other_func
{
read_trans_file(5);
}
it seems like the memory of pressurentries is overwritten after allocating memory for outputs. I remember that in previous versions i could access on some first ~7 elements of pressureentries.