Skip to content

Commit 4685080

Browse files
Don't realloc(nullptr) from PSRAM by default
Several Arduino APIs realloc(NULL) which is legal and equivalent to "malloc()", but the PSRAM logic was placing those malloc calls in PSRAM and not RAM because "0" < RAM_START. Ensure the realloc address is non-null and before RAM_START before using PSRAM.
1 parent 5fbda35 commit 4685080

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cores/rp2040/malloc-lock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extern "C" void *__wrap_realloc(void *mem, size_t size) {
8888
void *rc;
8989
noInterrupts();
9090
#ifdef RP2350_PSRAM_CS
91-
if (mem < __ram_start) {
91+
if (mem && (mem < __ram_start)) {
9292
rc = __psram_realloc(mem, size);
9393
} else {
9494
rc = __real_realloc(mem, size);
@@ -103,7 +103,7 @@ extern "C" void *__wrap_realloc(void *mem, size_t size) {
103103
extern "C" void __wrap_free(void *mem) {
104104
noInterrupts();
105105
#ifdef RP2350_PSRAM_CS
106-
if (mem < __ram_start) {
106+
if (mem && (mem < __ram_start)) {
107107
__psram_free(mem);
108108
} else {
109109
__real_free(mem);

0 commit comments

Comments
 (0)