Malloc - Incorrect Checksum for Freed Object

Discussion in 'Mac Programming' started by datscha, Feb 9, 2012.

  1. datscha macrumors newbie

    Jan 31, 2012
    Hi all,

    Still working on the same project, I have an error I never had before.

    Complex* fft(Complex* x)
        int N = sizeof(x)/sizeof(double);
        Complex *w_out;
        w_out = (Complex*) calloc(sizeof(Complex), N);
        fftw_complex *in, *out;
        in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
        out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
        fftw_plan p;
        for (int j = 0; j < N; j++)
            in[j][0] = x[j].GetReal();
            in[j][1] = x[j].GetImaginary();
        p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
        for (int i = 0; i < N; i++)
        fftw_free(in); fftw_free(out);
        return w_out;
    Above is the call from the Fast Fourier Transform, adapted to my program (cf. previous thread for the Complex class) and based on FFTW3 libraries.

    Further in my program, I call this function several times.
    One time in a function called fftMethod and two other times for frfftMethod.
    If the call is straight forward
     y = fft(x); 
    and works fine for the fftMethod. It returns me this weird looking Malloc error for the frfftMethod which obviously comes from the fftw_free commands.
    Of course when I try to remove those commands, I get a segmentation fault error.

    So if you guys have any idea of what might be wrong, I'm pretty stuck here.


    PS: I have a reasonable doubt concerning my declaration of int N in my fft function, but didn't seem to be a problem before.
  2. datscha thread starter macrumors newbie

    Jan 31, 2012
    Shame on me.

    Looks like it didn't like this kind of definition.

    My bad for the useless post!

    Newbie inside, bear with me ;)
  3. Sander macrumors 6502

    Apr 24, 2008
    So how did you solve this? Did you decide to make your fft() function take a std::vector of Complex?

    By the way, is there a reason you're not using the C++ std::complex data type?
  4. gnasher729 macrumors P6


    Nov 25, 2005
    Look at the line where N is calculated.

Share This Page