diff --git a/src/cli.c b/src/cli.c index cd4758ec..f2a8c739 100644 --- a/src/cli.c +++ b/src/cli.c @@ -163,7 +163,6 @@ main(int argc, char** argv) char* password = NULL; bool verbose = false; char* logfile = NULL; - bool do_free = true; int c; int option_index = 0; size_t size; @@ -218,7 +217,11 @@ main(int argc, char** argv) username = optarg; break; case 'P': - password = optarg; + password = strdup(optarg); + if (password == NULL) + { + errx(1, "Error allocating memory for password"); + } break; case 'L': logfile = optarg; @@ -533,20 +536,10 @@ main(int argc, char** argv) /* Password */ if (password == NULL) { - if (password != NULL) - { - free(password); - password = NULL; - } - printf("Password : "); password = pgagroal_get_password(); printf("\n"); } - else - { - do_free = false; - } for (int i = 0; i < strlen(password); i++) { @@ -676,7 +669,7 @@ main(int argc, char** argv) pgagroal_stop_logging(); pgagroal_destroy_shared_memory(shmem, size); - if (do_free) + if (password != NULL) { free(password); }