diff options
author | Patrick Georgi <patrick@georgi-clan.de> | 2014-10-02 10:16:26 +0200 |
---|---|---|
committer | Stephen Warren <swarren@nvidia.com> | 2014-10-02 17:07:09 -0600 |
commit | 4bc982c3a8f2a4b21e449fc0db93d46d505f7d95 (patch) | |
tree | 0df2ba849b993ff2382ed799d34033b783c9595e | |
parent | 141409fb208ef94de3b438eff2a87197714fbe65 (diff) | |
download | nvidia-cbootimage-4bc982c3a8f2a4b21e449fc0db93d46d505f7d95.tar.gz |
data_layout: improve memory handling
- free empty_blk if it's allocated and there's an error
- only free empty_blk if it's non-NULL. While POSIX
requests such free()s to be safe, some implementations
(eg Solaris) aren't compliant.
Found-by: Coverity Scan
Signed-off-by: Patrick Georgi <patrick@georgi-clan.de>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
-rw-r--r-- | src/data_layout.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/data_layout.c b/src/data_layout.c index 01f00ab..db0a0f0 100644 --- a/src/data_layout.c +++ b/src/data_layout.c @@ -1004,12 +1004,14 @@ write_block_raw(build_image_context *context) { size_t bytes = pages_to_write * context->page_size; - if (fwrite(data, 1, bytes, context->raw_file) != bytes) + if (fwrite(data, 1, bytes, context->raw_file) != bytes) { + if (empty_blk) free(empty_blk); return -1; + } } } - free(empty_blk); + if (empty_blk) free(empty_blk); return 0; } |