This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 426b77c9fcb11702be6210de4154a94c6e9e2fa0
Author: yinshengkai <[email protected]>
AuthorDate: Fri Jul 25 15:22:16 2025 +0800

    system/trace: Change stack variables to dynamic memory allocation
    
    trace_dump() kept its 1024-byte read buffer on the stack of the trace
    command.  Allocate it from the heap instead and free it once the dump is
    done.
    
    Assisted-by: Kiro:claude-opus-5-5
    Signed-off-by: yinshengkai <[email protected]>
---
 system/trace/trace_dump.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/system/trace/trace_dump.c b/system/trace/trace_dump.c
index 37d55c860..bbb85ea62 100644
--- a/system/trace/trace_dump.c
+++ b/system/trace/trace_dump.c
@@ -69,7 +69,7 @@ static void note_ioctl(int cmd, unsigned long arg)
 
 int trace_dump(FAR FILE *out, bool binary)
 {
-  uint8_t tracedata[1024];
+  uint8_t *tracedata = NULL;
   int ret;
   int fd;
 
@@ -95,6 +95,14 @@ int trace_dump(FAR FILE *out, bool binary)
         }
     }
 
+  tracedata = malloc(1024);
+  if (tracedata == NULL)
+    {
+      fprintf(stderr, "trace: cannot allocate memory\n");
+      close(fd);
+      return ERROR;
+    }
+
   /* Read and output all notes */
 
   while (1)
@@ -116,7 +124,7 @@ int trace_dump(FAR FILE *out, bool binary)
   /* Close note */
 
   close(fd);
-
+  free(tracedata);
   return ret;
 }
 

Reply via email to