4
I have this struct
in a data structure and need to free up memory with it used:
typedef struct
{
int capacityOfElements; //capacidade do vetor
int numberOfElements; //número de elementos presentes no vetor
int *data; //elementos do vetor
}tVector;
for this I am using the function free()
where theoretically it would release first V->data
and dps V
to release all memory used. But the call free(V->data)
gives the following error:
Error in `./V': free(): invalid next size (fast): 0x0000000001d82030
Aborted (core dumped)
someone knows how to fix it?
tVector* create(int n)
{
tVector* newVector = malloc(sizeof(tVector));
if(!newVector)
printf("error in the Malloc process for newVector.\n");
newVector->data = malloc(newVector->capacityOfElements *sizeof(int));
if(!(newVector->data))
printf("error in the Malloc process for newVector->data.\n");
newVector->capacityOfElements=n;
newVector->numberOfElements=0;
return newVector;
You instate tVector using malloc?
– Skywalker
yes, here follows the function in which malloc use
– dekmalunedek
Have you ever tried to free the memory of each one individually ?
– Edilson
newVector->capacityOfElements
no value is set when you do themalloc()
– pmg