Fixing realloc's edge case.#1937
Conversation
WalkthroughThis change corrects the logic for updating free block pointers and sizes when expanding memory allocations adjacent to the heap head in two custom realloc functions. The updates ensure that the new free block after expansion is properly linked within the free list and its size accurately reflects the remaining free memory. Changes
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (13)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/mips/openbios/kernel/alloc.c(1 hunks)src/mips/psyqo/src/alloc.c(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: macOS CI
src/mips/openbios/kernel/alloc.c
[error] 246-246: Compilation error: ‘delta’ undeclared (first use in this function) in function ‘multi_realloc’.
⏰ Context from checks skipped due to timeout of 90000ms (12)
- GitHub Check: pcsx-redux (aarch64-linux)
- GitHub Check: pcsx-redux (x86_64-linux)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: pcsx-redux (x86_64-linux)
- GitHub Check: pcsx-redux (aarch64-linux)
- GitHub Check: cross-arm64
- GitHub Check: toolchain
- GitHub Check: macos-build-and-test-toolchain
- GitHub Check: asan
- GitHub Check: coverage
- GitHub Check: aur-build
- GitHub Check: build
| new_block->next = head->next; | ||
| new_block->size = head->size - delta; |
There was a problem hiding this comment.
Fix compilation error: 'delta' undeclared.
There's a compilation error due to the undeclared variable delta on line 246.
The size calculation should be the amount of memory freed (old_size - size), not head->size - delta. Apply this diff:
new_block->next = head->next;
- new_block->size = head->size - delta;
+ new_block->size = old_size - size;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| new_block->next = head->next; | |
| new_block->size = head->size - delta; | |
| new_block->next = head->next; | |
| new_block->size = old_size - size; |
🧰 Tools
🪛 GitHub Actions: macOS CI
[error] 246-246: Compilation error: ‘delta’ undeclared (first use in this function) in function ‘multi_realloc’.
🤖 Prompt for AI Agents
In src/mips/openbios/kernel/alloc.c at lines 245-246, the variable 'delta' is
undeclared causing a compilation error. Replace 'head->size - delta' with the
correct size calculation 'old_size - size' to fix the error and correctly
compute the freed memory size.
| new_block->next = head->next; | ||
| new_block->size = head->size - delta; |
There was a problem hiding this comment.
Fix incorrect variable usage and scope issue.
Line 529 uses delta which is declared in a different conditional branch (line 542) and represents a different value (size - old_size for growing vs old_size - size needed for shrinking).
The size calculation should be the amount of memory freed when shrinking. Apply this diff:
new_block->next = head->next;
- new_block->size = head->size - delta;
+ new_block->size = old_size - size;The fix to new_block->next = head->next correctly links the new block to skip the current head.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| new_block->next = head->next; | |
| new_block->size = head->size - delta; | |
| new_block->next = head->next; | |
| new_block->size = old_size - size; |
🤖 Prompt for AI Agents
In src/mips/psyqo/src/alloc.c around lines 528 to 529, the variable delta used
for calculating new_block->size is incorrectly referenced from a different
conditional branch where it has a different meaning. To fix this, replace delta
with the correct calculation for shrinking, which is old_size - size, ensuring
the new block size correctly represents the freed memory. Also, keep the
assignment new_block->next = head->next to properly link the new block in the
list.
Revert "Fixing realloc's edge case." This reverts commit c4cd97f. .
No description provided.