Fix memory leak in scan cleanup when scan context is unavailable#302
Open
hobostay wants to merge 1 commit intotimescale:mainfrom
Open
Fix memory leak in scan cleanup when scan context is unavailable#302hobostay wants to merge 1 commit intotimescale:mainfrom
hobostay wants to merge 1 commit intotimescale:mainfrom
Conversation
When tp_rescan_cleanup_results() is called without a scan context, the function was logging a warning about memory leak but then only setting the pointer to NULL without actually freeing the memory. This fix ensures that pfree() is called to properly release the allocated memory even when scan_context is not available. - Add pfree() call for result_ctids before setting to NULL - Add pfree() call for result_scores before setting to NULL - Update warning message to reflect the actual behavior This prevents memory leaks in edge cases where scan context cleanup occurs in unusual scenarios (e.g., during error handling or certain rescan patterns).
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.
Summary
Fixes a memory leak in
tp_rescan_cleanup_results()that occurs whenscan_contextis unavailable.Problem
In
src/am/scan.c, thetp_rescan_cleanup_results()function has a code path that handles cleanup whenscan_contextis not available. The original code logged a warning about a memory leak but then only set the pointer to NULL without actually freeing the memory:This affected both
result_ctidsandresult_scoresallocations.Solution
Add
pfree()calls to properly release the allocated memory:Impact
This prevents memory leaks in edge cases where scan context cleanup occurs in unusual scenarios, such as:
The fix is minimal and safe - it only adds the missing
pfree()calls that should have been there.Test plan
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com