summaryrefslogtreecommitdiffstats
path: root/fdisk/sfdisk.c
diff options
context:
space:
mode:
authorSami Kerola2012-02-07 22:01:28 +0100
committerKarel Zak2012-02-08 13:39:09 +0100
commit823a6aa1183f2895cc39a21c3f198d884ba9c820 (patch)
tree7aae0a01d4422078af6957c11fe2412b48ad9dfd /fdisk/sfdisk.c
parentfdisk: remove redundant declaration [cppcheck] (diff)
downloadkernel-qcow2-util-linux-823a6aa1183f2895cc39a21c3f198d884ba9c820.tar.gz
kernel-qcow2-util-linux-823a6aa1183f2895cc39a21c3f198d884ba9c820.tar.xz
kernel-qcow2-util-linux-823a6aa1183f2895cc39a21c3f198d884ba9c820.zip
sfdisk: free variable which got the allocation [cppcheck]
[fdisk/sfdisk.c:358]: (error) Memory leak: ss [kzak@redhat.com: - free after error] Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisk/sfdisk.c')
-rw-r--r--fdisk/sfdisk.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c
index 6b87b4a97..6267652ff 100644
--- a/fdisk/sfdisk.c
+++ b/fdisk/sfdisk.c
@@ -291,7 +291,7 @@ restore_sectors(char *dev) {
int fdin = -1, fdout = -1;
int ct;
struct stat statbuf;
- char *ss0, *ss;
+ char *ss0 = NULL, *ss;
unsigned long sno;
if (stat(restore_sector_file, &statbuf) < 0) {
@@ -304,10 +304,12 @@ restore_sectors(char *dev) {
error(_("partition restore file has wrong size - not restoring\n"));
goto err;
}
- if (!(ss = (char *)malloc(statbuf.st_size))) {
+ if (!(ss0 = (char *)malloc(statbuf.st_size))) {
error(_("out of memory?\n"));
goto err;
}
+ ss = ss0;
+
fdin = open(restore_sector_file, O_RDONLY);
if (fdin < 0) {
perror(restore_sector_file);
@@ -328,7 +330,6 @@ restore_sectors(char *dev) {
goto err;
}
- ss0 = ss;
ct = statbuf.st_size / 516;
while (ct--) {
sno = chars_to_ulong((unsigned char *)ss);
@@ -342,6 +343,7 @@ restore_sectors(char *dev) {
ss += 516;
}
free(ss0);
+ ss0 = NULL;
if (!reread_disk_partition(dev, fdout)) /* closes fdout */
goto err;
@@ -350,6 +352,7 @@ restore_sectors(char *dev) {
return 1;
err:
+ free(ss0);
if (fdin >= 0)
close(fdin);
if (fdout >= 0)