Skip to content

Fix/cs builder context leak#4903

Closed
JohnLangford wants to merge 5 commits intomasterfrom
fix/cs-builder-context-leak
Closed

Fix/cs builder context leak#4903
JohnLangford wants to merge 5 commits intomasterfrom
fix/cs-builder-context-leak

Conversation

@JohnLangford
Copy link
Copy Markdown
Member

No description provided.

CreateBuilder() allocates a builder_context on the heap but
DeleteBuilder() never called delete on it, leaking ~40 bytes per
namespace per example.

Closes #4900
The features_have_names/hashes/values helpers called ->size() after
IsFieldPresent() without checking for nullptr. On Windows debug builds,
intentionally malformed flatbuffers (from BadNamespace_* tests) could
have a present-but-null field, causing SEH access violations (0xc0000005).
start_ns_extent() was called before validation but end_ns_extent() was
only called on the success path. When RETURN_NS_PARSER_ERROR fired, the
extent was left open (end_index == 0), causing crashes on Windows debug
builds (SEH 0xc0000005) when the example was later cleaned up.

Uses a scope_exit guard to ensure end_ns_extent is always called.
- DeleteWorkspace() allocated workspace_context with new but never freed
  it, leaking memory on every workspace creation/deletion cycle.
- IOWriterAdapter in SaveModel(Stream) and IOReaderAdapter in
  CreateWorkspaceWithModelData could be garbage collected during the
  native call since no managed references remained after GetVTable().
  Added GC.KeepAlive() to prevent premature collection.

Addresses remaining memory leaks reported in #4900.
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