sfdisk: fix memory leak and related to using invalid memoryin sfdisk_print_partition()#4459
Open
Leefancy wants to merge 1 commit into
Open
sfdisk: fix memory leak and related to using invalid memoryin sfdisk_print_partition()#4459Leefancy wants to merge 1 commit into
Leefancy wants to merge 1 commit into
Conversation
karelzak
reviewed
Jun 30, 2026
| if (0 == rc) { | ||
| printf("%12s : ", data); | ||
| free(data); | ||
| } |
Collaborator
There was a problem hiding this comment.
The function fdisk_partition_to_string() keeps &data NULL on error, so you can use:
if (fdisk_partition_to_string(pa, sf->cxt, FDISK_FIELD_DEVICE, &data) == 0)
printf("%12s : ", data);
free(data);
karelzak
reviewed
Jun 30, 2026
| printf("(%s) ", data); | ||
| rc = fdisk_partition_to_string(pa, sf->cxt, FDISK_FIELD_SIZE, &data); | ||
| if (0 == rc) { | ||
| printf("%12s : ", data); |
Collaborator
There was a problem hiding this comment.
Please, be careful with copy & paste, it's "(%s) ".
karelzak
reviewed
Jun 30, 2026
| printf("%s\n", data); | ||
| rc = fdisk_partition_to_string(pa, sf->cxt, FDISK_FIELD_TYPE, &data); | ||
| if (0 == rc) { | ||
| printf("%12s : ", data); |
…print_partition() Signed-off-by: lijian <lijian01@kylinos.cn>
Author
|
Thanks for the review feedback. I don't think we can simplify the code this way, for two reasons:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The function fdisk_partition_to_string() dynamically allocates memory
for the returned string. In sfdisk_print_partition(), this function is
called multiple times in succession to print various partition fields
(DEVICE, START, END, SIZE, and TYPE).