Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,15 +528,19 @@ int rpm_process(GSList *install, GSList *update, GSList *erase) {

int question(char* question, int possibilities) {
int status = NO, repeat = 1;
char answer;
char *answer = NULL, letter;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me there is a memory leak because answer is never freed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thank you.

switch(possibilities)
{
case YES_NO:
while(repeat) {
rds_log(logQUESTION, "%s\n[y/n]: ", question);
scanf("%c", &answer);
if(getline(&answer, &size, stdin) == -1){
// TODO error message after log reimpmelentation
}else{
letter = answer[0];
}

switch(answer)
switch(letter)
{
case 'y':
status = YES;
Expand All @@ -549,7 +553,6 @@ int question(char* question, int possibilities) {

default:
rds_log(logWARNING, "Unsupported answer. You should choose y for yes or n for no.\n");
scanf("%c", &answer); //eliminating enter
break;
}
}
Expand All @@ -559,9 +562,13 @@ int question(char* question, int possibilities) {
while(repeat)
{
rds_log(logQUESTION, "%s\n[y/n/d]: ", question);
scanf("%c", &answer);

switch(answer)
if(getline(&answer, &size, stdin) == -1){
// TODO error message after log reimpmelentation
}else{
letter = answer[0];
}

switch(letter)
{
case 'y':
status = YES;
Expand All @@ -579,12 +586,16 @@ int question(char* question, int possibilities) {

default:
rds_log(logWARNING, "Unsupported answer. You should choose y for yes, n for no or d for download only.\n");
scanf("%c", &answer); //eliminating enter
break;
}
}
break;
}

if(answer != NULL){

free(answer);
}

return status;
}