Skip to content

Fix unsafe resource lifetimes found by repository audit - #1524

Open
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/resource-lifetime-audit
Open

Fix unsafe resource lifetimes found by repository audit#1524
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/resource-lifetime-audit

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

Description

Fix four independent resource-lifetime defects found by a repository-wide audit of first-party cleanup and ownership paths:

  • Do not release hostNameRef returned by CFDictionaryGetValue; it is borrowed from the proxy dictionary. Also avoid indexing an empty proxy array.
  • Keep a newly constructed LogManagerImpl in a unique_ptr until insertion into the global manager registry succeeds, preventing an exception-path leak.
  • Make EventProperty copy self-assignment a no-op instead of clearing its own source storage and then dereferencing it.
  • Pair the two new[] allocations in ETW provider GUID generation with delete[] rather than scalar delete.

The audit excluded vendored/generated code. WinInet and curl cancellation lifetime findings are intentionally not duplicated here because #1520 already rewrites those ownership paths.

Validation

  • Configured and built the Linux SDK/unit-test targets with MATSDK_WARNINGS_AS_ERRORS=ON.
  • Ran the targeted EventPropertiesTests suite.
  • Ran all 645 Linux unit tests.
  • Performed a focused ownership review of the resulting diff; an initially considered Objective-C configuration cleanup was removed because custom log managers retain that configuration by reference and require a broader lifecycle redesign.

Correct four independent ownership defects that can over-release borrowed CoreFoundation data, leak a newly created manager on registry allocation failure, corrupt self-assigned EventProperty values, or pair array allocations with scalar deletion.

Files changed:
- examples/cpp/MacProxy/main.cpp: preserve borrowed proxy values and guard empty proxy arrays.
- lib/api/LogManagerFactory.cpp: retain manager ownership until registry insertion succeeds.
- lib/system/EventProperty.cpp: make copy self-assignment safe.
- lib/tracing/api/DebugProviders.hpp: pair new[] buffers with delete[].
- tests/unittests/EventPropertiesTests.cpp: cover EventProperty self-assignment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d7d2f27a-7339-4585-ad02-9f89ce20ef40
@bmehta001
bmehta001 requested a review from a team as a code owner August 24, 2026 03:00
@bmehta001 bmehta001 self-assigned this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant