rimage: Fix some memory leak error

Handle pointers and memory when error happens.

Signed-off-by: Pan Xiuli <xiuli.pan@linux.intel.com>
This commit is contained in:
Pan Xiuli 2017-12-20 22:10:19 +08:00 committed by Liam Girdwood
parent 0866b2a13e
commit 6b59f8f698
1 changed files with 13 additions and 5 deletions

View File

@ -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,8 @@ found:
if (image.in_fd == NULL) {
fprintf(stderr, "error: unable to open %s for reading %d\n",
image.in_file, errno);
ret = -EINVAL;
goto out;
}
/* open outfile for writing */
@ -291,14 +294,19 @@ found:
if (image.out_fd == NULL) {
fprintf(stderr, "error: unable to open %s for writing %d\n",
image.out_file, errno);
ret = -EINVAL;
goto out;
}
/* write data */
ret = write_elf_data(&image);
out:
/* close files */
fclose(image.out_fd);
if (image.in_fd)
fclose(image.in_fd);
if (image.out_fd)
fclose(image.out_fd);
return ret;
}