diff --git a/AUTHORS b/AUTHORS index 3707d5a4..a81701ca 100644 --- a/AUTHORS +++ b/AUTHORS @@ -8,4 +8,5 @@ Luca Ferrari Nikita Bugrovsky Lawrence Wu Yongting You <2010youy01@gmail.com> -Ashutosh Sharma \ No newline at end of file +Ashutosh Sharma +Henrique de Carvalho \ No newline at end of file diff --git a/src/cli.c b/src/cli.c index c9bdc6c6..8d7a6ca1 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,10 +669,7 @@ main(int argc, char** argv) pgagroal_stop_logging(); pgagroal_destroy_shared_memory(shmem, size); - if (do_free) - { - free(password); - } + free(password); if (verbose) {