Skip to content

fix: external free - #17074

Merged
sukki37 merged 1 commit into
matrixorigin:mainfrom
huby2358:t3
Jun 21, 2024
Merged

sukki37 merged 1 commit into
matrixorigin:mainfrom
huby2358:t3

Conversation

@huby2358

@huby2358 huby2358 commented Jun 21, 2024 •

Copy link
Copy Markdown
Contributor

User description

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

#16725

issue #

What this PR does / why we need it:

fix external_scan free panic when MO Checkin Regression On TKE


PR Type

Bug fix


Description

  • Fixed a panic issue in the Free method of pkg/sql/colexec/external/types.go by reordering the operations.
  • Ensured allocation analysis is performed before setting arg.ctr to nil.

Changes walkthrough 📝

Relevant files
Bug fix
types.go
Fix panic in `Free` method by reordering operations           

pkg/sql/colexec/external/types.go

  • Fixed the order of operations in the Free method to prevent panic.
  • Moved the allocation analysis to occur before setting arg.ctr to nil.
  • +3/-4     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review [1-5] 2
    🧪 Relevant tests No
    🔒 Security concerns No
    ⚡ Key issues to review Possible Bug:
    Ensure that arg.ctr is not accessed after being set to nil. The reordering of operations in the Free method now sets arg.ctr to nil before the method exits, which is safer in terms of memory management. However, ensure that there are no further usages of arg.ctr after it has been set to nil in any subsequent code that might be executed in the same context.

    @matrix-meow matrix-meow added the size/XS Denotes a PR that changes [1, 9] lines label Jun 21, 2024
    @mergify mergify Bot added the kind/bug Something isn't working label Jun 21, 2024
    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Move the anal.Alloc call inside the if arg.ctr != nil block to prevent potential nil pointer dereference

    The anal.Alloc call should be placed inside the if arg.ctr != nil block to avoid potential
    nil pointer dereference if arg.ctr is nil.

    pkg/sql/colexec/external/types.go [159-161]

    -anal := proc.GetAnalyze(arg.GetIdx(), arg.GetParallelIdx(), arg.GetParallelMajor())
    -anal.Alloc(int64(arg.ctr.maxAllocSize))
    -arg.ctr = nil
    +if arg.ctr != nil {
    +    anal := proc.GetAnalyze(arg.GetIdx(), arg.GetParallelIdx(), arg.GetParallelMajor())
    +    anal.Alloc(int64(arg.ctr.maxAllocSize))
    +    arg.ctr = nil
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly identifies a potential nil pointer dereference risk in the new code and proposes a safer implementation by checking if arg.ctr is not nil before accessing its properties. This change is crucial for preventing runtime errors.

    8

    @sukki37
    sukki37 merged commit e36343f into matrixorigin:main Jun 21, 2024
    fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Bug fix kind/bug Something isn't working Review effort [1-5]: 2 size/XS Denotes a PR that changes [1, 9] lines

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    4 participants