Skip to content

fix issue #898 MainLoop Segmentation fault due to dangle pointer - #910

Merged
gaoxueyu merged 1 commit into
IvorySQL:masterfrom
OreoYang:master
Oct 9, 2025
Merged

gaoxueyu merged 1 commit into
IvorySQL:masterfrom
OreoYang:master

Conversation

@OreoYang

@OreoYang OreoYang commented Oct 9, 2025 •

Copy link
Copy Markdown
Contributor

Since code restructure remove break not noticed; re-add it.

Summary by CodeRabbit

  • Refactor
    • Streamlined an internal cleanup loop to exit earlier, reducing unnecessary iterations during resource cleanup.
    • Minor efficiency improvement in edge cases; does not alter commands, outputs, or user workflows.
    • No changes to error messages, configuration, or compatibility; behavior remains consistent for all user interactions.

@coderabbitai

coderabbitai Bot commented Oct 9, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

A break statement was added to the cleanup loop in src/bin/psql/mainloop.c to exit immediately after freeing the final print_list item and the list structure when length reaches 0. No other logic or files were modified.

Changes

Cohort / File(s) Summary of edits
psql cleanup loop tweak
src/bin/psql/mainloop.c
Inserted a break inside the cleanup loop to exit once pl->length is 0 after freeing the last item and the list; no other behavioral changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

I nudge one loop to hop out quick,
A tidy break—so clean, so slick.
No extra hops, no trails to sweep,
The list sleeps soundly, freed and deep.
Thump-thump! I twitch—review complete.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary change by referencing the specific segmentation fault in the MainLoop caused by a dangling pointer and ties it to the relevant issue number, which directly corresponds to the added break statement that prevents the fault.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1dc7a76 and 156be54.

📒 Files selected for processing (1)
  • src/bin/psql/mainloop.c (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: meson_build (ubuntu-latest)
  • GitHub Check: oracle_pg_regression (ubuntu-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: contrib_regression
  • GitHub Check: oracle_regression (ubuntu-latest)
  • GitHub Check: pg_regression (ubuntu-latest)
🔇 Additional comments (1)
src/bin/psql/mainloop.c (1)

644-661: Critical fix: Prevents use-after-free segmentation fault.

The added break statement at line 659 is essential to prevent a use-after-free bug. After freeing pl at line 658, the loop must exit immediately. Without this break, the next iteration would evaluate the loop condition while (pl->length > 0), which dereferences the freed pl pointer, causing a segmentation fault.

This correctly addresses the dangling pointer issue mentioned in the PR title.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gaoxueyu
gaoxueyu merged commit 36b9f81 into IvorySQL:master Oct 9, 2025
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.

2 participants