~ chicken-core (chicken-5) 636f245fa9588e48a3f5d5cf5ff348acafd784c1
commit 636f245fa9588e48a3f5d5cf5ff348acafd784c1 Author: Evan Hanson <evhan@foldling.org> AuthorDate: Sun Dec 2 14:19:08 2018 +1300 Commit: felix <felix@call-with-current-continuation.org> CommitDate: Tue Dec 4 18:34:25 2018 +0100 Fix empty line and memory leak in debugger GET_TRACE replies Previously, all of the debugger's trace responses would include an empty string in addition to the "real" entries, and the memory allocated for the trace dump itself was never freed. The first issue is fixed by sending only the newline-terminated chunks of the trace buffer (which avoids including the empty string between the final newline and the subsequent null terminator), and the second issue is fixed by simply freeing the trace buffer at the end. Signed-off-by: felix <felix@call-with-current-continuation.org> diff --git a/dbg-stub.c b/dbg-stub.c index 71051f09..feed4980 100644 --- a/dbg-stub.c +++ b/dbg-stub.c @@ -461,23 +461,17 @@ send_event(int event, C_char *loc, C_char *val, C_char *cloc) break; case C_DEBUG_REPLY_GET_TRACE: - str = C_dump_trace(0); - C_strlcpy(rw_buffer, "(* \"", sizeof(rw_buffer)); - ptr = rw_buffer + 4; - - while(*str != '\0') { - if(*str == '\n') { - C_strlcpy(ptr, "\")\n", 4); - send_string(rw_buffer); - C_strlcpy(rw_buffer, "(* \"", sizeof(rw_buffer)); - ptr = rw_buffer + 4; - ++str; - } - else *(ptr++) = *(str++); + str = ptr = C_dump_trace(0); + + while((n = C_strcspn(ptr, "\n"))) { + ptr[ n++ ] = '\0'; + send_string("(* \""); + send_string(ptr); + send_string("\")\n"); + ptr += n; } - C_strlcpy(ptr, "\")\n", 4); - send_string(rw_buffer); + free(str); break; default: terminate("invalid reply code");Trap