fix: heap-allocate memory_read buffer to prevent stack overflow
CLI task stack is 4KB; the 4096-byte stack buffer in cmd_memory_read was overflowing and corrupting the heap. Use malloc instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -102,12 +102,17 @@ static int cmd_set_model(int argc, char **argv)
|
|||||||
/* --- memory_read command --- */
|
/* --- memory_read command --- */
|
||||||
static int cmd_memory_read(int argc, char **argv)
|
static int cmd_memory_read(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char buf[4096];
|
char *buf = malloc(4096);
|
||||||
if (memory_read_long_term(buf, sizeof(buf)) == ESP_OK && buf[0]) {
|
if (!buf) {
|
||||||
|
printf("Out of memory.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (memory_read_long_term(buf, 4096) == ESP_OK && buf[0]) {
|
||||||
printf("=== MEMORY.md ===\n%s\n=================\n", buf);
|
printf("=== MEMORY.md ===\n%s\n=================\n", buf);
|
||||||
} else {
|
} else {
|
||||||
printf("MEMORY.md is empty or not found.\n");
|
printf("MEMORY.md is empty or not found.\n");
|
||||||
}
|
}
|
||||||
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user