I'm writing a function in C that takes as input an array and gives as output two arrays. The function will write to an array that is passed in as an argument. As a "fail safe" to prevent memory errors, I want to check whether or not the pointer passed into the function is a valid memory address or not and if it is, free it. Here's the code I have so far, with the part that I'm still unsure about stubbed out:
int fft( double* signal, double* real, double* imag, int size ) {
double retVal;
/*initialize output arrays*/
if( /*real is a valid memory address */ ) {
free( real );
}
How do I check that real
is a valid memory address that will not seg fault when I try to free it?