I found out today that when I try to free
a pointer that has been reallocated the program crashes and prints "Segmentation Fault".
A realloc()
is called on this pointer (array) in order to sizeup the array and merge the old array and another one.
Further in the program I must free
it, how can I bypass this problem without having to make some sort of buffer array, adding the 2 other arrays to it and then to free them?
PARTICLE
: structurenewCount
: sum of the size of the old array + array that is being added
Code:
group1->particleList =
(PARTICLE *) realloc(group1->particleList, newCount * sizeof(PARTICLE));