私は C プログラミングが初めてで、問題の解決策を見つけることができませんでした。コードは機能しますが (他のプログラムに含めることができました)、calloc() によって割り当てられたメモリを解放しようとすると、次のエラーが返されます。
free(): invalid next size (normal):
メモリ アドレスのように見えるものが続きます。私は mpc ライブラリを使用しています (任意精度の複素数用)。これは、エラーを繰り返す最小のプログラムです。
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include <mpfr.h>
#include <mpc.h>
int N = 10;
int precision = 512;
int main(void) {
mpc_t *dets2;
dets2 = (mpc_t*)calloc(N-2,sizeof(mpc_t));
for (int i = 0; i<=N-2; i++) {
mpc_init2(dets2[i],512); //initialize all complex numbers
mpc_set_str(dets2[i],"1",0,MPFR_RNDN); //set all the numbers to one
}
free(dets2); //release the memory occupied by those numbers
return 0;
}
ご協力いただきありがとうございます!