fatfs: Free path copy when f_open fails (FATFS_FSTAT) - #5245
Open
herbenderbler wants to merge 545 commits into
Open
fatfs: Free path copy when f_open fails (FATFS_FSTAT)#5245herbenderbler wants to merge 545 commits into
herbenderbler wants to merge 545 commits into
Conversation
subrepo: subdir: "lib/Prusa-Error-Codes" merged: "d64eb1056d" upstream: origin: "git@github.com:prusa3d/Prusa-Error-Codes.git" branch: "master" commit: "d64eb1056d" git-subrepo: version: "0.4.9" origin: "???" commit: "???"
As these happen fast & outside of the print, the motor may skip, but that's OK. Don't report as filament stuck (because likely it isn't). BFW-7545
And proceed with the test anyway. BFW-7542.
Rework the ADC FS logic to get rid of the fixed FS span. BFW-5338
Not using fs_span, get rid of it BFW-5338
I will be adding REF_INS in the next commit BFW-5338
It is no longer relevant to the config store. The CalibrateInserted is now a bit mesy, but I intend to rework the whole calibration in the upcoming PR, so I would keep it this way for now. BFW-5338
The selftest expects the fsensor to report HasFilament/NoFilament right after nins calibration is done, even though ins calibration is not yet done. This forced me to reintroduce filament sensor span just for that situation. Temporary solution till the new selftest comes. BFW-5338
subrepo: subdir: "lib/Prusa-Error-Codes" merged: "a0138327b4" upstream: origin: "git@github.com:prusa3d/Prusa-Error-Codes.git" branch: "master" commit: "a0138327b4" git-subrepo: version: "0.4.9" origin: "???" commit: "???"
BFW-7465 BFW-7547
…ing frequency) BFW-7413
BFW-7413
Add alignment_issue screen Adjust finish screen Edit texts disable motors when appropriate BFW-7413
When running low on data in precise stepper or phase stepping, try to wake up the move interrupt early, to refill. * We hope there are some move segments cached to be processed even in case planner is currently blocking more of them. * We hope there will be enough time or that the stall will be as short as possible if there isn't; certainly better situation than waiting for up to a whole 1ms. * Remove the critical section from the planner side again - even if the moves are blocked, we may be able to do the refill from the cached data. Remove it with just an atomic flag so the move ISR will just skip looking there while it's being updated. BFW-7936, BFW-7873.
With the running-dry wakeup, we can lower the queues again a bit - we don't necessarily have to survive for a whole 1ms in that case. BFW-7936, BFW-7873.
Instead of limiting the amount of segments processed to at most 1 per 1ms (or one call now), process as much as possible. We've observed segments with shorter times than 1ms. Even when we have the wakeup on running dry, it's better to keep the buffers full and have smaller amount of the interrupt calls for performance. BFW-7873.
Instead of guessing if taking moves out of planner made progress indirectly, just return it from the function. This is a slight optimization of the move_isr loop. BFW-7873.
Recent changes made it overflow from time to time (they either made the stack of some interrupt function larger or the chance of multiple interrupt stacking on each other got higher). Trying to add 100 bytes (+alignment), as we don't have a direct way to measure how much we need. BFW-7873.
Cherry-pick with added C1 values Co-Authored-By: Dano Pernis <danopernis@gmail.com> Co-Authored-By: Ondřej Veselý <o.vesely42@gmail.com> BFW-7395 BFW-8021
BFW-7395 BFW-8021
BFW-7395 BFW-8021
BFW-7395 BFW-8021
More granular tracking of the printer's setup progress. And display only the ones missing when printer si selectively factory reset. BFW-7867
BFW-7945
BFW-8021
Crash recovery was hard-switching to Resuming_Begin print state, which: - Did not trigger media_prefetch_call() - Skipped the resuming buffering phase. Using print_resume unifies the functionality and print_resume makes sure that all necessary steps are done. BFW-8082
herbenderbler
force-pushed
the
fix-failed-fopen-leak
branch
2 times, most recently
from
April 14, 2026 14:38
acf354f to
93eb8b6
Compare
When FATFS_FSTAT is enabled, open_r allocates a path copy for fstat/fchmod. If f_open fails, close_r never runs, so the buffer was leaked. Free f->path on the error path and clear the pointer, matching close_r.
herbenderbler
force-pushed
the
fix-failed-fopen-leak
branch
from
April 14, 2026 14:38
93eb8b6 to
1d4cdc6
Compare
herbenderbler
marked this pull request as ready for review
April 14, 2026 14:40
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.
Description
When
FATFS_FSTATis enabled,open_rallocates a heap copy of the opened path forfstat/fchmod. Iff_openfailed, that buffer was never freed becauseclose_rdoes not run on a failed open. Each failed open leakedstrlen(path) + 1bytes until reboot. This change frees the path copy on thef_openerror path and clears the pointer, matching cleanup inclose_r.Implementation Details
src/buddy/filesystem_fatfs.cpp: Inopen_r, insideif (result != FR_OK), add aFATFS_FSTAT-guarded block that callsfree(f->path)when non-null and setsf->pathtonullptrbefore existingFR_NO_FILESYSTEMhandling andreturn -1.Test/Documentation
FATFS_FSTAT, build a target that uses the FatFS devoptab, and open a path that makesf_openfail (e.g. missing file on USB); confirm heap does not grow on repeated attempts (or use a host-side Memcheck model of the same control flow).