-
-
Notifications
You must be signed in to change notification settings - Fork 123
introduce psram-aware malloc functions (backport of upstream #4895) #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mdev
Are you sure you want to change the base?
Changes from all commits
15b6907
c6a4e28
d273835
a861a31
b78d5e6
e714ede
98c9788
31e56ae
4c93146
9408564
735047f
78a964c
62e4cab
1eaad1b
60f8648
67c70a2
68dbd5e
69946e4
381ad56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -454,13 +454,13 @@ static bool alocateFFTBuffers(void) { | |
| USER_PRINT(F("\nFree heap ")); USER_PRINTLN(ESP.getFreeHeap()); | ||
| #endif | ||
|
|
||
| if (vReal) free(vReal); // should not happen | ||
| if (vImag) free(vImag); // should not happen | ||
| if ((vReal = (float*) calloc(samplesFFT, sizeof(float))) == nullptr) return false; // calloc or die | ||
| if ((vImag = (float*) calloc(samplesFFT, sizeof(float))) == nullptr) return false; | ||
| if (vReal) d_free(vReal); // should not happen | ||
| if (vImag) d_free(vImag); // should not happen | ||
| if ((vReal = (float*) d_calloc(samplesFFT, sizeof(float))) == nullptr) return false; // calloc or die | ||
| if ((vImag = (float*) d_calloc(samplesFFT, sizeof(float))) == nullptr) return false; | ||
| #ifdef FFT_MAJORPEAK_HUMAN_EAR | ||
| if (pinkFactors) free(pinkFactors); | ||
| if ((pinkFactors = (float*) calloc(samplesFFT, sizeof(float))) == nullptr) return false; | ||
| if (pinkFactors) p_free(pinkFactors); | ||
| if ((pinkFactors = (float*) p_calloc(samplesFFT, sizeof(float))) == nullptr) return false; | ||
| #endif | ||
|
Comment on lines
+457
to
464
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Free partially allocated FFT buffers on failure. If 🛠️ Proposed fix- if ((vImag = (float*) d_calloc(samplesFFT, sizeof(float))) == nullptr) return false;
+ if ((vImag = (float*) d_calloc(samplesFFT, sizeof(float))) == nullptr) {
+ d_free(vReal);
+ vReal = nullptr;
+ return false;
+ }
`#ifdef` FFT_MAJORPEAK_HUMAN_EAR
- if ((pinkFactors = (float*) p_calloc(samplesFFT, sizeof(float))) == nullptr) return false;
+ if ((pinkFactors = (float*) p_calloc(samplesFFT, sizeof(float))) == nullptr) {
+ d_free(vReal);
+ d_free(vImag);
+ vReal = nullptr;
+ vImag = nullptr;
+ return false;
+ }
`#endif`🤖 Prompt for AI Agents |
||
|
|
||
| #ifdef SR_DEBUG | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -352,7 +352,7 @@ void RotaryEncoderUIUsermod::sortModesAndPalettes() { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| byte *RotaryEncoderUIUsermod::re_initIndexArray(int numModes) { | ||||||||||||||||||||||||||
| byte *indexes = (byte *)malloc(sizeof(byte) * numModes); | ||||||||||||||||||||||||||
| byte *indexes = (byte *)d_calloc(numModes, sizeof(byte)); | ||||||||||||||||||||||||||
| for (byte i = 0; i < numModes; i++) { | ||||||||||||||||||||||||||
| indexes[i] = i; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
354
to
358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard If 🛠️ Proposed fix- byte *indexes = (byte *)d_calloc(numModes, sizeof(byte));
- for (byte i = 0; i < numModes; i++) {
+ byte *indexes = (byte *)d_calloc(numModes, sizeof(byte));
+ if (!indexes) return nullptr;
+ for (byte i = 0; i < numModes; i++) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
@@ -364,7 +364,7 @@ byte *RotaryEncoderUIUsermod::re_initIndexArray(int numModes) { | |||||||||||||||||||||||||
| * They don't end in '\0', they end in '"'. | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| const char **RotaryEncoderUIUsermod::re_findModeStrings(const char json[], int numModes) { | ||||||||||||||||||||||||||
| const char **modeStrings = (const char **)malloc(sizeof(const char *) * numModes); | ||||||||||||||||||||||||||
| const char **modeStrings = (const char **)d_calloc(numModes, sizeof(const char *)); | ||||||||||||||||||||||||||
| uint8_t modeIndex = 0; | ||||||||||||||||||||||||||
| bool insideQuotes = false; | ||||||||||||||||||||||||||
| // advance past the mark for markLineNum that may exist. | ||||||||||||||||||||||||||
|
|
@@ -380,7 +380,7 @@ const char **RotaryEncoderUIUsermod::re_findModeStrings(const char json[], int n | |||||||||||||||||||||||||
| insideQuotes = !insideQuotes; | ||||||||||||||||||||||||||
| if (insideQuotes) { | ||||||||||||||||||||||||||
| // We have a new mode or palette | ||||||||||||||||||||||||||
| modeStrings[modeIndex] = (char *)(json + i + 1); | ||||||||||||||||||||||||||
| if (modeIndex < numModes) modeStrings[modeIndex] = (char *)(json + i + 1); //WLEDMM prevent array bounds violation | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||
| case '[': | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle
d_mallocfailure before reading the program filed_malloccan return nullptr (especially with MIN_HEAP_SIZE constraints). The current code immediately reads intoprogramText, which will crash on allocation failure. Please guard and bail out cleanly.🛠️ Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents