fiasco: Call free at correct place

This commit is contained in:
Pali Rohár committed 2014-09-29 00:42:52 +02:00
1 parent d88176dbef
commit 23b916bcc9
1 file changed
+11 -7
+11 -7
View File
@@ -493,8 +493,10 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
if ( image->layout ) { if ( image->layout ) {
layout_name = calloc(1, strlen(name) + strlen(".layout") + 1); layout_name = calloc(1, strlen(name) + strlen(".layout") + 1);
if ( ! layout_name ) if ( ! layout_name ) {
free(name);
ALLOC_ERROR_RETURN(-1); ALLOC_ERROR_RETURN(-1);
}
sprintf(layout_name, "%s.layout", name); sprintf(layout_name, "%s.layout", name);
@@ -512,8 +514,6 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
} }
} }
free(name);
image_seek(image, 0); image_seek(image, 0);
while ( 1 ) { while ( 1 ) {
size = image_read(image, buf, sizeof(buf)); size = image_read(image, buf, sizeof(buf));
@@ -522,7 +522,10 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
WRITE_OR_FAIL(name, fd, buf, size); WRITE_OR_FAIL(name, fd, buf, size);
} }
close(fd); free(name);
if ( ! simulate )
close(fd);
if ( image->layout ) { if ( image->layout ) {
@@ -534,11 +537,12 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
} }
} }
free(layout_name);
WRITE_OR_FAIL(layout_name, fd, image->layout, (int)strlen(image->layout)); WRITE_OR_FAIL(layout_name, fd, image->layout, (int)strlen(image->layout));
close(fd); free(layout_name);
if ( ! simulate )
close(fd);
} }