mio :: poll是否会产生真正的内存泄漏,我可以忽略它吗?

时间:2019-08-06 13:35:16

标签: rust valgrind

我想轮询字符设备以检查中断。我的代码似乎可以正常工作,但是在Valgrind下运行代码时出现内存泄漏。

我将代码简化为一个最小示例,仍然会导致内存泄漏:

use mio::Poll;

fn main() {
    // Construct a new `Poll` handle
    let _poll = Poll::new().unwrap();
}

我希望_poll超出范围时会干净地删除。但是,在Valgrind下运行时,上面的代码将产生以下输出:

==4771== Memcheck, a memory error detector
==4771== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4771== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==4771== Command: ./target/debug/poll_test
==4771== 
==4771== Syscall param epoll_ctl(event) points to uninitialised byte(s)
==4771==    at 0x49B2BAC: epoll_ctl (syscall-template.S:78)
==4771==    by 0x10DDC7: mio::sys::unix::epoll::Selector::register (epoll.rs:98)
==4771==    by 0x10FA0B: <mio::sys::unix::eventedfd::EventedFd<'a> as mio::event_imp::Evented>::register (eventedfd.rs:97)
==4771==    by 0x10FDFB: <mio::sys::unix::io::Io as mio::event_imp::Evented>::register (io.rs:65)
==4771==    by 0x10E97F: <mio::sys::unix::awakener::pipe::Awakener as mio::event_imp::Evented>::register (awakener.rs:63)
==4771==    by 0x10AB7F: mio::poll::Poll::new (poll.rs:665)
==4771==    by 0x10A797: poll_test::main (main.rs:5)
==4771==    by 0x10A62B: std::rt::lang_start::{{closure}} (rt.rs:64)
==4771==    by 0x1190AF: {{closure}} (rt.rs:49)
==4771==    by 0x1190AF: std::panicking::try::do_call (panicking.rs:297)
==4771==    by 0x11B407: __rust_maybe_catch_panic (lib.rs:87)
==4771==    by 0x119A8B: try<i32,closure> (panicking.rs:276)
==4771==    by 0x119A8B: catch_unwind<closure,i32> (panic.rs:388)
==4771==    by 0x119A8B: std::rt::lang_start_internal (rt.rs:48)
==4771==    by 0x10A5FB: std::rt::lang_start (rt.rs:64)
==4771==  Address 0xbde4b10c is on thread 1's stack
==4771==  in frame #1, created by mio::sys::unix::epoll::Selector::register (epoll.rs:91)
==4771==  Uninitialised value was created by a stack allocation
==4771==    at 0x10DD40: mio::sys::unix::epoll::Selector::register (epoll.rs:91)
==4771== 
==4771== 
==4771== HEAP SUMMARY:
==4771==     in use at exit: 20 bytes in 1 blocks
==4771==   total heap usage: 18 allocs, 17 frees, 2,137 bytes allocated
==4771== 
==4771== 20 bytes in 1 blocks are still reachable in loss record 1 of 1
==4771==    at 0x484A004: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==4771== 
==4771== LEAK SUMMARY:
==4771==    definitely lost: 0 bytes in 0 blocks
==4771==    indirectly lost: 0 bytes in 0 blocks
==4771==      possibly lost: 0 bytes in 0 blocks
==4771==    still reachable: 20 bytes in 1 blocks
==4771==         suppressed: 0 bytes in 0 blocks
==4771== 
==4771== For counts of detected and suppressed errors, rerun with: -v
==4771== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 3)

为什么此代码会产生内存泄漏?我可以解决吗?如果没有,我可以放心地忽略它吗?

0 个答案:

没有答案