C矩阵行列式计算-内存泄漏

C矩阵行列式计算-内存泄漏,c,matrix,memory-leaks,C,Matrix,Memory Leaks,我的计算矩阵行列式的程序仍然存在内存泄漏。我不知道怎么修理它。我已经标记了valgrind发现无效的代码行。矩阵是从文本文件加载的。文件示例(第一个数字是矩阵的大小): 3. 1 2 3 4 5 6 7 8 9 Valgrind输出: ==3292== Memcheck, a memory error detector ==3292== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==3292== Usin

我的计算矩阵行列式的程序仍然存在内存泄漏。我不知道怎么修理它。我已经标记了valgrind发现无效的代码行。矩阵是从文本文件加载的。文件示例(第一个数字是矩阵的大小):

3.
1 2 3 
4 5 6
7 8 9
Valgrind输出:

==3292== Memcheck, a memory error detector
==3292== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3292== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==3292== Command: ./macierz
==3292== 
Matrix Size: 4
1.000000 2.000000 3.000000 4.000000 
4.000000 5.000000 6.000000 5.000000 
7.000000 8.000000 15.000000 5.000000 
5.000000 4.000000 6.000000 7.000000 
Determinant: 303.000000
==3292== 
==3292== HEAP SUMMARY:
==3292==     in use at exit: 104 bytes in 8 blocks
==3292==   total heap usage: 48 allocs, 40 frees, 6,864 bytes allocated
==3292== 
==3292== 24 bytes in 3 blocks are definitely lost in loss record 1 of 3
==3292==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-    amd64-linux.so)
==3292==    by 0x400BCB: det(double**, int) (main.c:99)
==3292==    by 0x400C9E: det(double**, int) (main.c:116)
==3292==    by 0x400C9E: det(double**, int) (main.c:116)
==3292==    by 0x400D7A: main (main.c:140)
==3292== 
==3292== 32 bytes in 1 blocks are definitely lost in loss record 2 of 3
==3292==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-    amd64-linux.so)
==3292==    by 0x400BCB: det(double**, int) (main.c:99)
==3292==    by 0x400D7A: main (main.c:140)
==3292== 
==3292== 48 bytes in 4 blocks are definitely lost in loss record 3 of 3
==3292==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-    amd64-linux.so)
==3292==    by 0x400BCB: det(double**, int) (main.c:99)
==3292==    by 0x400C9E: det(double**, int) (main.c:116)
==3292==    by 0x400D7A: main (main.c:140)
==3292== 
==3292== LEAK SUMMARY:
==3292==    definitely lost: 104 bytes in 8 blocks
==3292==    indirectly lost: 0 bytes in 0 blocks
==3292==      possibly lost: 0 bytes in 0 blocks
==3292==    still reachable: 0 bytes in 0 blocks
==3292==         suppressed: 0 bytes in 0 blocks
==3292== 
==3292== For counts of detected and suppressed errors, rerun with: -v
==3292== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
代码:

#包括
#包括
无效显示矩阵(双**矩阵,整数n){\
puts(“显示矩阵”);
int i,j;

对于(i=0;i您的第99行是无用的:

  double** minor = (double**)calloc(n, sizeof(double*));  // <---- Line 99
double**minor=(double**)calloc(n,sizeof(double*);//2
:内存泄漏:指针被覆盖 删除它,你会没事的

  double** minor = (double**)calloc(n, sizeof(double*));  // <---- Line 99