Fix LSP memory leak on goto definition - #10860
Open
JRI98 wants to merge 1 commit into
Open
Conversation
Contributor
Greptile SummaryThe PR establishes explicit ownership and cleanup for goto-definition result URIs, including the hover fallback, and strengthens the built-in definition integration test.
Confidence Score: 5/5The PR appears safe to merge, with definition-result URI ownership consistently established and released across the changed paths. Every definition result reaching the new cleanup sites contains an allocator-owned URI, allocation failures remain propagated, and each result is released exactly once.
|
| Filename | Overview |
|---|---|
| src/lsp/syntax.zig | Introduces a uniform owned-URI contract for definition results and releases hover fallback results after use. |
| src/lsp/handlers/definition.zig | Releases definition query results after serializing the location response. |
| src/lsp/test/handler_integration_tests.zig | Reworks the built-in definition fixture and now requires a valid Builtin.roc response. |
| src/lsp/test/test_syntax_driver.zig | Adds the cleanup method required by the generic definition handler interface. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Definition query] --> B{Definition target}
B -->|Current document| C[Duplicate current URI]
B -->|External or built-in module| D[Allocate URI with pathToUri]
C --> E[Owned DefinitionResult]
D --> E
E --> F{Consumer}
F -->|Definition handler| G[Build response]
F -->|Hover fallback| H[Resolve referenced definition]
G --> I[deinit frees URI]
H --> I
Reviews (1): Last reviewed commit: "Fix LSP memory leak on goto definition" | Re-trigger Greptile
JRI98
enabled auto-merge
August 19, 2026 00:04
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.
Goto-definition queries returning URIs to external or built-in modules dynamically allocated memory that was never released by the handler or internal query fallbacks, resulting in a memory leak detected during server shutdown.
This was addressed by establishing an explicit ownership and cleanup lifecycle for definition query results across the definition handler and hover resolution fallback.
Fixes #10857