[Sound-open-firmware] [PATCH] rimage: Fix some memory leak error
From: Pan Xiuli xiuli.pan@linux.intel.com
Handle pointers and memory when error happens.
Signed-off-by: Pan Xiuli xiuli.pan@linux.intel.com --- rimage/rimage.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/rimage/rimage.c b/rimage/rimage.c index af57f5a..f5b5404 100644 --- a/rimage/rimage.c +++ b/rimage/rimage.c @@ -208,10 +208,11 @@ static int write_elf_data(struct image *image) goto out; }
- free(image->prg); - free(image->section); - out: + if (image->prg) + free(image->prg); + if (image->section) + free(image->section); return ret; }
@@ -283,6 +284,7 @@ found: if (image.in_fd == NULL) { fprintf(stderr, "error: unable to open %s for reading %d\n", image.in_file, errno); + goto out; }
/* open outfile for writing */ @@ -291,14 +293,18 @@ found: if (image.out_fd == NULL) { fprintf(stderr, "error: unable to open %s for writing %d\n", image.out_file, errno); + goto out; }
/* write data */ ret = write_elf_data(&image);
+out: /* close files */ - fclose(image.out_fd); - fclose(image.in_fd); + if (image.in_fd) + fclose(image.in_fd); + if (image.out_fd) + fclose(image.out_fd);
return ret; }
participants (1)
-
Xiuli Pan