diff --git a/ask.c b/ask.c index 7b47178..77b7f39 100644 --- a/ask.c +++ b/ask.c @@ -231,6 +231,7 @@ static char *get_input(FILE *in, FILE *out, const char *prompt, const char *init case '\r': goto finished; case KEY_CTRL_C: case KEY_ESC: + cleanup: free(buf); buf = NULL; picked = NULL; @@ -283,7 +284,10 @@ static char *get_input(FILE *in, FILE *out, const char *prompt, const char *init buf[--len] = 0; } break; - case KEY_DELETE: case KEY_CTRL_D: + case KEY_CTRL_D: + if (len == 0) goto cleanup; + // fallthrough + case KEY_DELETE: if (b < len) { memmove(buf+b, buf+b+1, (size_t)(len-b)); buf[--len] = 0;