mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
fdasd: Fix memory leak in yes_no() function
The yes_no() function was leaking memory when returning early from the loop, as the 'answer' buffer allocated by getline() was not freed before the return statements. Restructure the function to use a single exit point, ensuring free(answer) is always called before returning. Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Volkan Unal <vunal@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -387,20 +387,28 @@ static int yes_no(char *question_str)
|
|||||||
ssize_t bytes_read;
|
ssize_t bytes_read;
|
||||||
char *answer;
|
char *answer;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
int rc;
|
||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
answer = NULL;
|
answer = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("%s (y/n): ", question_str);
|
printf("%s (y/n): ", question_str);
|
||||||
bytes_read = getline(&answer, &size, stdin);
|
bytes_read = getline(&answer, &size, stdin);
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0) {
|
||||||
return -1;
|
rc = -1;
|
||||||
if (answer[0] == 'y')
|
break;
|
||||||
return 0;
|
}
|
||||||
if (answer[0] == 'n')
|
if (answer[0] == 'y') {
|
||||||
return 1;
|
rc = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (answer[0] == 'n') {
|
||||||
|
rc = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(answer);
|
free(answer);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *fdasd_partition_type(char *dsname)
|
static char *fdasd_partition_type(char *dsname)
|
||||||
|
|||||||
Reference in New Issue
Block a user