Skip to content

Conversation

@david-cermak
Copy link
Collaborator

@david-cermak david-cermak commented Oct 24, 2025

Closes #917

Fixes memory leaks and use-after-free in mDNS question handling by ensuring dynamically allocated strings are freed when questions are discarded early.

Changes:

  • Stop freeing domain: q->domain points to MDNS_DEFAULT_DOMAIN, so it is not freed.

  • Switch to dynamic allocations in (Allocate host, service, and proto with mdns_mem_strndup() and set own_dynamic_memory = true)

    • _mdns_append_host_question
    • _mdns_create_probe_packet
    • _mdns_create_search_packet
  • Add cleanup in early discard paths:

    • _mdns_append_host_question: free host when duplicate detected
    • _mdns_create_probe_packet: free host/service/proto when duplicate detected or host is NULL
    • _mdns_remove_scheduled_service_packets: free host/service/proto when removing scheduled packets

Prevents leaks when questions are discarded before being queued (duplicates, NULL values, or early removal). Ensures consistency with the own_dynamic_memory flag and avoids accessing freed memory.
This aligns with the pattern used in _mdns_free_tx_packet() for cleaning up dynamically allocated question fields.

@david-cermak david-cermak self-assigned this Oct 24, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG in MDNS memory leak and stom data (IDFGH-16665)

1 participant