Fix unsafe resource lifetimes found by repository audit - #1524
Merged
bmehta001 merged 3 commits intoAug 28, 2026
Conversation
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
Baiju Meswani (baijumeswani)
approved these changes
Aug 28, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request addresses several resource-lifetime and ownership defects identified by an audit, tightening correctness around CoreFoundation borrow semantics, exception-safety during log manager creation, safe self-assignment for EventProperty, and correct array deallocation in ETW GUID generation.
Changes:
- Add a self-assignment guard to
EventProperty::operator=and add a unit test to prevent regressions. - Make
LogManagerFactory::Createexception-safe by usingstd::unique_ptruntil registry insertion succeeds. - Fix mismatched
new[]/deletein ETW provider GUID generation and correct CoreFoundation lifetime handling in the Mac proxy example.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unittests/EventPropertiesTests.cpp | Adds a regression test covering EventProperty self-assignment behavior. |
| lib/tracing/api/DebugProviders.hpp | Fixes incorrect deallocation by pairing new[] with delete[]. |
| lib/system/EventProperty.cpp | Makes copy self-assignment a no-op to avoid clearing and then reading from the same object. |
| lib/api/LogManagerFactory.cpp | Uses std::unique_ptr to avoid leaks if insertion into the manager registry throws. |
| examples/cpp/MacProxy/main.cpp | Avoids indexing an empty proxy array and stops releasing a borrowed CFDictionaryGetValue result. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix four independent resource-lifetime defects found by a repository-wide audit of first-party cleanup and ownership paths:
hostNameRefreturned byCFDictionaryGetValue; it is borrowed from the proxy dictionary. Also avoid indexing an empty proxy array.LogManagerImplin aunique_ptruntil insertion into the global manager registry succeeds, preventing an exception-path leak.EventPropertycopy self-assignment a no-op instead of clearing its own source storage and then dereferencing it.new[]allocations in ETW provider GUID generation withdelete[]rather than scalardelete.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
MATSDK_WARNINGS_AS_ERRORS=ON.EventPropertiesTestssuite.