Skip to content

Possible memory leak (?) #35

@AFx3

Description

@AFx3

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.

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions