From 00a759b0c751b180b5679b36bd738ed2efbe8df9 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2026 14:51:04 +0700 Subject: [PATCH] trace load: keep the current trace when loading a file fails The trace buffer was cleared before the load, so a missing or empty file lost the trace already loaded. Loading straight into gs_trace also left it dangling when loadFile_safe() freed it on a short read, to be freed again by the next clear or load. Load into a local buffer and swap it in on success. Co-Authored-By: Claude Opus 5.5 --- client/src/cmdtrace.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index f4afa1e9e..4b037647d 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -1582,14 +1582,16 @@ static int CmdTraceLoad(const char *Cmd) { CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); CLIParserFree(ctx); - ClearTraceBuffer(); // maybe better to not clobber this until we have successful load? - + // keep the current trace until the new one has loaded + uint8_t *trace = NULL; size_t len = 0; - if (loadFile_safe(filename, ".trace", (void **)&gs_trace, &len) != PM3_SUCCESS) { + if (loadFile_safe(filename, ".trace", (void **)&trace, &len) != PM3_SUCCESS) { PrintAndLogEx(FAILED, "Could not open file " _YELLOW_("%s"), filename); return PM3_EIO; } + ClearTraceBuffer(); + gs_trace = trace; gs_traceLen = (uint32_t)len; PrintAndLogEx(SUCCESS, "Recorded Activity (TraceLen = " _YELLOW_("%u") " bytes)", gs_traceLen);