summaryrefslogtreecommitdiffstats
path: root/src/fiasco.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2014-11-18 18:49:32 +0100
committerPali Rohár <pali.rohar@gmail.com>2014-11-18 18:49:32 +0100
commit89566f559b6fba25de2f3c7a7064417e10ee81aa (patch)
tree60340c32bda388da768f2665794eab68d6a1cde5 /src/fiasco.c
parentcfd3b662a58961b9c8307dfc95846ee5f8309042 (diff)
download0xFFFF-89566f559b6fba25de2f3c7a7064417e10ee81aa.tar.bz2
fiasco: Fix memory leaks
Diffstat (limited to 'src/fiasco.c')
-rw-r--r--src/fiasco.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/fiasco.c b/src/fiasco.c
index 74d089f..993b43d 100644
--- a/src/fiasco.c
+++ b/src/fiasco.c
@@ -413,6 +413,7 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) {
WRITE_OR_FAIL(file, fd, "2", 1); /* 2 - device & hwrevs */
WRITE_OR_FAIL(file, fd, &device_hwrevs_bufs[i][0], 1);
WRITE_OR_FAIL(file, fd, device_hwrevs_bufs[i]+1, ((uint8_t *)(device_hwrevs_bufs[i]))[0]);
+ /* FIXME: memory leak: device_hwrevs_bufs */
}
free(device_hwrevs_bufs);
@@ -513,6 +514,8 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
fd = open(name, O_RDWR|O_CREAT|O_TRUNC, 0644);
if ( fd < 0 ) {
ERROR_INFO("Cannot create output file %s", name);
+ free(name);
+ free(layout_name);
return -1;
}
}
@@ -522,7 +525,15 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
size = image_read(image, buf, sizeof(buf));
if ( size == 0 )
break;
- WRITE_OR_FAIL(name, fd, buf, size);
+ if ( ! simulate ) {
+ if ( write(fd, buf, size) != (ssize_t)size ) {
+ ERROR_INFO_STR(name, "Cannot write %d bytes", size);
+ close(fd);
+ free(name);
+ free(layout_name);
+ return -1;
+ }
+ }
}
free(name);
@@ -538,9 +549,16 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
ERROR_INFO("Cannot create layout file %s", layout_name);
return -1;
}
- }
- WRITE_OR_FAIL(layout_name, fd, image->layout, (int)strlen(image->layout));
+ size = strlen(image->layout);
+
+ if ( write(fd, image->layout, size) != (ssize_t)size ) {
+ ERROR_INFO_STR(layout_name, "Cannot write %d bytes", size);
+ close(fd);
+ free(layout_name);
+ return -1;
+ }
+ }
free(layout_name);