ITADN

Possible memory leak (?)

#35OpenAFx3 创建于 2025-05-27
A
AFx3commented
Hello! I won't bother you. I think the function syscall_getrusage() in the main may be a source of a memory leak, due to the Box::into_raw. The Box::from_raw(ptr) nor explicit drop release it in the code. ```rust fn syscall_getrusage() { let time = libc::timeval { tv_sec: 0, tv_usec: 0, }; let rusage = Box::new(libc::rusage { ru_utime: time, ru_stime: time, ru_maxrss: 0, .... }); let ptr = Box::into_raw(rusage); // Ownership forgotten, no drop instruction let result = benchmark( || {}, |_test| { unsafe { libc::getrusage(0, ptr); } true }, ) .unwrap(); result.print_results("Sycall getrusage(2)", 0); } ``` Probably invoking the from_raw after that test would be a good choice? Because running napkin_math --evaluate syscall_getrusage -n 1000000 may consume a lot of memory. Probably I'm wrong but what do you think?
1 条评论