Skip to content

Unintended handle context leak in Rust #5520

@nishanthkarthik

Description

@nishanthkarthik

Describe the bug

The Rust bindings make a distinction between owned and ref types, for instance, Connection and ConnectionRef. On the server side, a listener callback receives a ConnectionRef for the NewConnection event. However, the callback handler attached to a ConnectionRef is not automatically cleaned up internally.

Affected OS

  • Windows
  • Linux
  • macOS
  • Other (specify below)

Additional OS information

No response

MsQuic version

main

Steps taken to reproduce bug

  1. Modify the example to allocate a large Box<[u8; N]> inside the connection handler closure
  2. Watch the memory usage grow for each new connection

Expected behavior

Setting connection_ref.set_callback_handler(handler) should automatically destroy the handler, if present. For every ConnectionRef, I assume someone owns a Connection internally. This conn: Connection should ideally invoke the cleanup.

Actual outcome

The handler leaks. The example below provides a way to handle this, but I am not sure if this is the idiomatic way to clean up resources.

unsafe { Connection::from_raw(conn.as_raw()) };

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions