AmendHub

Download:

jcs

/

subtext

/

amendments

/

652

settings: Plug some leaks


jcs made amendment 652 1 day ago
--- settings.c Tue Jan 23 16:29:43 2024 +++ settings.c Tue Sep 22 16:14:59 2026 @@ -173,9 +173,12 @@ get_input: (sf->type == CONFIG_TYPE_PASSWORD ? '*' : 0)); session_output(s, "\r\n", 2); session_flush(s); - if (input == NULL || s->ending) + if (input == NULL || s->ending) { + if (input != NULL) + xfree(&input); break; - + } + if (strlen(input) >= sf->max) { session_printf(s, "%s is too long (%d max, ^C to cancel)", sf->name, @@ -184,6 +187,7 @@ get_input: goto get_input; } strlcpy(new_data + sf->off, input, sf->max); + xfree(&input); any_changes = true; break; case CONFIG_TYPE_SHORT: @@ -201,22 +205,24 @@ get_input: input = session_field_input(s, 10, 10, initial, false, 0); session_output(s, "\r\n", 2); session_flush(s); - if (input == NULL || s->ending) + if (input == NULL || s->ending) { + if (input != NULL) + xfree(&input); break; + } lval = atol(input); + xfree(&input); if (lval < sf->min) { session_printf(s, "%s must be %ld or higher (^C to cancel)\r\n", sf->name, sf->min); - xfree(&input); goto get_input; } if (lval > sf->max) { session_printf(s, "%s must be %ld or less (^C to cancel)\r\n", sf->name, sf->max); - xfree(&input); goto get_input; } if (sf->type == CONFIG_TYPE_LONG) { @@ -275,9 +281,12 @@ get_input: input = session_field_input(s, 16, 16, initial, false, 0); session_output(s, "\r\n", 2); session_flush(s); - if (input == NULL || s->ending) + if (input == NULL || s->ending) { + if (input != NULL) + xfree(&input); break; - + } + if (input[0] == '\0') { lval = 0; xfree(&input); @@ -313,7 +322,8 @@ get_input: } done: - xfree(&dopts); + if (dopts != NULL) + xfree(&dopts); if (any_changes) { *result = new_data;