diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2014-09-29 00:42:52 +0200 |
---|---|---|
committer | Pali Rohár <pali.rohar@gmail.com> | 2014-09-29 00:42:52 +0200 |
commit | 23b916bcc9de857a1c88718cc2315813efbcb4e4 (patch) | |
tree | 795ee882cd496d7d572e7feca9fdc79324a42707 /src/fiasco.c | |
parent | d88176dbefc4610105e6e22e50be01926d136f43 (diff) | |
download | 0xFFFF-23b916bcc9de857a1c88718cc2315813efbcb4e4.tar.bz2 |
fiasco: Call free at correct place
Diffstat (limited to 'src/fiasco.c')
-rw-r--r-- | src/fiasco.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/fiasco.c b/src/fiasco.c index 721785e..2d22747 100644 --- a/src/fiasco.c +++ b/src/fiasco.c @@ -493,8 +493,10 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) { if ( image->layout ) { layout_name = calloc(1, strlen(name) + strlen(".layout") + 1); - if ( ! layout_name ) + if ( ! layout_name ) { + free(name); ALLOC_ERROR_RETURN(-1); + } 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); while ( 1 ) { 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); } - close(fd); + free(name); + + if ( ! simulate ) + close(fd); 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)); - close(fd); + free(layout_name); + + if ( ! simulate ) + close(fd); } |