在我的程序的一个步骤中,我需要对图像进行卷积。为此,我正在使用提供的功能fftw3
。当我跑步时valgrind
在我的程序中,我得到了这个堆栈跟踪。我的函数叫做convolve
它运行fftw3
's fftw_plan_dft_r2c_2d
两次(一次在图像上,一次在卷积核上。为了使其更具可读性,我删除了所有地址和进程ID。
HEAP SUMMARY:
in use at exit: 62,280 bytes in 683 blocks
total heap usage: 178,271 allocs, 177,588 frees, 36,617,058 bytes allocated
3,304 (24 direct, 3,280 indirect) bytes in 1 blocks are definitely lost in loss record 129 of 131
at : malloc (vg_replace_malloc.c:291)
by : fftw_malloc_plain (in ./prog)
by : fftw_mkapiplan (in ./prog)
by : fftw_plan_many_dft_r2c (in ./prog)
by : fftw_plan_dft_r2c (in ./prog)
by : fftw_plan_dft_r2c_2d (in ./prog)
by : convolve (freqdomain.c:199)
by : convolve (conv.c:290)
by : main (main.c:332)
3,304 (24 direct, 3,280 indirect) bytes in 1 blocks are definitely lost in loss record 130 of 131
at : malloc (vg_replace_malloc.c:291)
by : fftw_malloc_plain (in ./prog)
by : fftw_mkapiplan (in ./prog)
by : fftw_plan_many_dft_r2c (in ./prog)
by : fftw_plan_dft_r2c (in ./prog)
by : fftw_plan_dft_r2c_2d (in ./prog)
by : convolve (freqdomain.c:203)
by : convolve (conv.c:290)
by : main (main.c:332)
LEAK SUMMARY:
definitely lost: 48 bytes in 2 blocks
indirectly lost: 6,560 bytes in 60 blocks
possibly lost: 0 bytes in 0 blocks
still reachable: 55,672 bytes in 621 blocks
suppressed: 0 bytes in 0 blocks
Reachable blocks (those to which a pointer was found) are not shown.
To see them, rerun with: --leak-check=full --show-leak-kinds=all
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 4 from 4)
根据手册的建议,完成后我已经使用了fftw_free
and fftw_destroy_plan
。我想看看我能对此做些什么还是这是一个内部问题fftw3
?既然没有释放malloc
位于 FFTW 源代码深处。
编辑:包含 fftw_cleanup() 之后
下面你可以看到diff
我添加后fftw_cleanup()
.
[me@mycomputer]$ diff NoCleanup WithCleanup
2,3c2,3
< in use at exit: 62,280 bytes in 683 blocks
< total heap usage: 178,271 allocs, 177,588 frees, 36,617,058 bytes allocated
---
> in use at exit: 9,008 bytes in 66 blocks
> total heap usage: 178,271 allocs, 178,205 frees, 36,617,058 bytes allocated
5c5
< 3,304 (24 direct, 3,280 indirect) bytes in 1 blocks are definitely lost in loss record 129 of 131
---
> 3,304 (24 direct, 3,280 indirect) bytes in 1 blocks are definitely lost in loss record 39 of 40
16c16
< 3,304 (24 direct, 3,280 indirect) bytes in 1 blocks are definitely lost in loss record 130 of 131
---
> 3,304 (24 direct, 3,280 indirect) bytes in 1 blocks are definitely lost in loss record 40 of 40
31c31
< still reachable: 55,672 bytes in 621 blocks
---
> still reachable: 2,400 bytes in 4 blocks
的数量still reachable
退出时使用的字节数显着减少,释放的数量也显着减少malloc
s 增加了。但主要错误(3,304 (24 direct, 3,280 indirect) bytes in 1 blocks are definitely lost
)仍然存在。