I am declaring an array of void pointers. Each of which points to a value of arbitary type.
void **values; // Array of void pointers to each value of arbitary type
Initializing values as follows:
values = (void**)calloc(3,sizeof(void*)); //can initialize values as: values = new void* [3]; int ival = 1; float fval = 2.0; char* str = 'word'; values[0] = (void*)new int(ival); values[1] = (void*)new float(fval); values[2] = (void*)str; //Trying to Clear the memory allocated free(*values); //Error: *** glibc detected *** simpleSQL: free(): invalid pointer: 0x080611b4 //Core dumped delete[] values*; //warning: deleting 'void*' is undefined //Similar Error.
Now how do I free/delete the memory allocated for values ( the array of void pointers)?
You have 3 things that are dynamically allocated that need to be freed in 2 different ways:
Note that since
stris not dynamically allocated it should not (actually cannot) be freed.A couple of notes:
sizeof(void)was meant to besizeof(void*)since what you have won’t compile