diff options
| author | Tristan Riehs <tristan.riehs@inria.fr> | 2026-08-02 19:29:38 +0200 |
|---|---|---|
| committer | Tristan Riehs <tristan.riehs@inria.fr> | 2026-08-02 19:33:47 +0200 |
| commit | e61e95d1699ffe04cab3a7caa952c3425fd1e5bb (patch) | |
| tree | 397ae76a4319e0ed7aaff51302ae1b1fbaeead09 /src | |
| parent | cb2e54162f127615732e456b4f2cdc8224ad6f15 (diff) | |
Do not forget to free readline result
Diffstat (limited to 'src')
| -rw-r--r-- | src/input.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/input.c b/src/input.c index 65ec3a7..94777bb 100644 --- a/src/input.c +++ b/src/input.c @@ -10,18 +10,25 @@ int prompt_yes_no(void) { - char *line; + char *line = NULL; int attempts = 0; + int ret = 0; do { line = readline(" [Y/n] "); char input = line[0]; - if (input == '\n'/*no input*/ || input == 'y' || input == 'Y') - return 1; - else if (input == 'n' || input == 'N') - return 0; + if (input == '\n'/*no input*/ || input == 'y' || input == 'Y') { + ret = 1; + break; + } + else if (input == 'n' || input == 'N') { + break; + } attempts++; } while(attempts < 3); - return 0; + if (line != NULL) { + free(line); + } + return ret; } void remove_ending_newline(char *str) |
