From ed32f73e988461a365c1a34fa5dca9cdbc788705 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Tue, 13 Mar 2018 11:00:44 -0500 Subject: [PATCH] Use another pointer to retain the original address to free This also resolves an issue where we weren't attempting to free the duplicated string when returning early. --- src/vm_debug.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/vm_debug.c b/src/vm_debug.c index 017425f..5c9d071 100644 --- a/src/vm_debug.c +++ b/src/vm_debug.c @@ -199,17 +199,18 @@ vm_debug_prompt() void vm_debug_execute(const char *str) { - char *tok, *ebuf; + char *tok, *ebuf, *orig; vm_debug_cmd *cmd; vm_debug_args args; - ebuf = strdup(str); + orig = ebuf = strdup(str); cmd = NULL; tok = vm_debug_next_arg(&ebuf); // No input if (tok == NULL) { + free(orig); return; } @@ -217,6 +218,7 @@ vm_debug_execute(const char *str) // No command found if (cmd == NULL) { + free(orig); return; } @@ -236,6 +238,7 @@ vm_debug_execute(const char *str) // But if this is -1, then something went wrong if (args.addr2 == -1) { + free(orig); return; } @@ -246,6 +249,7 @@ vm_debug_execute(const char *str) // Oh no if (args.addr1 == -1) { + free(orig); return; } @@ -258,7 +262,7 @@ vm_debug_execute(const char *str) cmd->handler(&args); - free(ebuf); + free(orig); } /*