Skip to content

Is it possible to generate a warning about std::process::Command::spawn() returned Child is never waited? #10754

Closed
@Originalimoc

Description

@Originalimoc

What it does

If there is no wait on the Child handle(and/or before it goes out of scope, the destructor won't wait() it either.), generate a warning about possible consequences: zombie process.

Lint Name

process_child_not_waited

Category

No response

Advantage

No response

Drawbacks

None.

Example

thread::spawn(move || {
                std::process::Command::new(&command[0])
                .args(&command[1..])
                .spawn()
                .unwrap_or_else(|e| panic!("Failed to execute {}: {}", command.join(" "), e));
            });

Could be written as:

thread::spawn(move || {
                let child = std::process::Command::new(&command[0])
                .args(&command[1..])
                .spawn()
                .unwrap_or_else(|e| panic!("Failed to execute {}: {}", command.join(" "), e));
                child.wait();
            });

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions