From 23b916bcc9de857a1c88718cc2315813efbcb4e4 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Mon, 29 Sep 2014 00:42:52 +0200 Subject: fiasco: Call free at correct place --- src/fiasco.c | 18 +++++++++++------- 1 file 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); } -- cgit v1.2.3