8000 fdisk: fix possible memory leak · util-linux/util-linux@138117a · GitHub
[go: up one dir, main page]

Skip to content

Commit 138117a

Browse files
committed
fdisk: fix possible memory leak
Signed-off-by: Karel Zak <kzak@redhat.com> (cherry picked from commit 7171968)
1 parent b5787cc commit 138117a

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

disk-utils/fdisk.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change 8000
@@ -652,27 +652,24 @@ static int strtosize_sectors(const char *str, unsigned long sector_size,
652652
size_t len = strlen(str);
653653
int insec = 0;
654654
int rc;
655+
char *buf = NULL;
655656

656657
if (!len)
657658
return 0;
658659

659660
if (str[len - 1] == 'S' || str[len - 1] == 's') {
660661
insec = 1;
661-
str = strndup(str, len - 1); /* strip trailing 's' */
662+
str = buf = strndup(str, len - 1); /* strip trailing 's' */
662663
if (!str)
663664
return -errno;
664665
}
665666

666667
rc = strtosize(str, res);
667-
if (rc)
668-
return rc;
669-
670-
if (insec) {
668+
if (rc == 0 && insec)
671669
*res *= sector_size;
672-
free((void *)str);
673-
}
674670

675-
return 0;
671+
free(buf);
672+
return rc;
676673
}
677674

678675
void resize_partition(struct fdisk_context *cxt)

0 commit comments

Comments
 (0)
0