我正在尝试按照此处概述的说明在 C++ 中异步读取和写入磁盘(使用 Ubuntu 10.04 中的 posix aio 库):aio tutorial。我可以异步读写,但恐怕会有某种小的内存泄漏。我的 valgrind 输出显示有 288 个可能丢失的字节和 3,648 个仍然可以访问的字节。这些数字似乎与实际从文件中读取的字节数无关。我找不到消除这种泄漏的位置或方法——它甚至看起来像是 aio 库的问题。有没有人见过这个?完整的 valgrind 输出如下。提前致谢。
==22330== ==22330== 堆摘要: ==22330== 在退出时使用:3 个块中的 3,936 个字节 ==22330== 总堆使用量:25 分配,22 释放,15,648 字节分配 ==22330== ==22330== 1 个块中的 64 个字节在丢失记录 1 of 3 中仍然可以访问 ==22330== 在 0x4C274A8:malloc (vg_replace_malloc.c:236) ==22330== by 0x4C27522: realloc (vg_replace_malloc.c:525) ==22330== 由 0x504CAF1: __aio_enqueue_request (aio_misc.c:127) ==22330== 0x504D25A:aio_read (aio_read.c:30) ==22330== by 0x406EB7: baio::read(std::string, char*, long) (baio_unix.cxx:58) ==22330== by 0x40613E: test_read_helper(char*) (test_read.cxx:16) ==22330== by 0x4063E1: test_read() (test_read.cxx:54) ==22330== by 0x40664C: test_read_main(int, char**) (test_read.cxx:74) ==22330== by 0x40959D: testlib_run_test_unit(unsigned long, int, char**) (testlib_main.cxx:116) ==22330== by 0x4097A9: testlib_main(int, char**) (testlib_main.cxx:155) ==22330== by 0x4060B4: main (test_driver.cxx:12) ==22330== ==22330== 1 个块中的 288 个字节可能在丢失记录 2 of 3 中丢失 ==22330== 在 0x4C267CC: calloc (vg_replace_malloc.c:467) ==22330== 0x4012395:_dl_allocate_tls (dl-tls.c:300) ==22330== by 0x4E34728: pthread_create@@GLIBC_2.2.5 (allocatestack.c:561) ==22330== 由 0x504C9A8: __aio_enqueue_request (aio_misc.h:60) ==22330== 0x504D25A:aio_read (aio_read.c:30) ==22330== by 0x406EB7: baio::read(std::string, char*, long) (baio_unix.cxx:58) ==22330== by 0x40613E: test_read_helper(char*) (test_read.cxx:16) ==22330== by 0x4063E1: test_read() (test_read.cxx:54) ==22330== by 0x40664C: test_read_main(int, char**) (test_read.cxx:74) ==22330== by 0x40959D: testlib_run_test_unit(unsigned long, int, char**) (testlib_main.cxx:116) ==22330== by 0x4097A9: testlib_main(int, char**) (testlib_main.cxx:155) ==22330== by 0x4060B4: main (test_driver.cxx:12) ==22330== ==22330== 1 个块中的 3,584 个字节在丢失记录 3 of 3 中仍然可以访问 ==22330== 在 0x4C267CC: calloc (vg_replace_malloc.c:467) ==22330== 由 0x504CA27: __aio_enqueue_request (aio_misc.c:139) ==22330== 0x504D25A:aio_read (aio_read.c:30) ==22330== by 0x406EB7: baio::read(std::string, char*, long) (baio_unix.cxx:58) ==22330== by 0x40613E: test_read_helper(char*) (test_read.cxx:16) ==22330== by 0x4063E1: test_read() (test_read.cxx:54) ==22330== by 0x40664C: test_read_main(int, char**) (test_read.cxx:74) ==22330== by 0x40959D: testlib_run_test_unit(unsigned long, int, char**) (testlib_main.cxx:116) ==22330== by 0x4097A9: testlib_main(int, char**) (testlib_main.cxx:155) ==22330== by 0x4060B4: main (test_driver.cxx:12) ==22330== ==22330== 泄漏摘要: ==22330== 肯定丢失:0 个块中的 0 个字节 ==22330== 间接丢失:0 个块中的 0 个字节 ==22330== 可能丢失:1 块 288 字节 ==22330== 仍然可以访问:2 个块中的 3,648 个字节 ==22330== 抑制:0 个块中的 0 个字节