From patchwork Thu Oct 2 08:16:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Georgi X-Patchwork-Id: 395848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C0058140180 for ; Thu, 2 Oct 2014 18:22:13 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751334AbaJBIWL (ORCPT ); Thu, 2 Oct 2014 04:22:11 -0400 Received: from georgi-clan.de ([78.47.195.38]:44988 "EHLO georgi-clan.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751544AbaJBIWI (ORCPT ); Thu, 2 Oct 2014 04:22:08 -0400 Received: from office.lan (drms-4d0def9c.pool.mediaWays.net [77.13.239.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: patrick) by georgi-clan.de (Postfix) with ESMTPSA id 9386F2201BC; Thu, 2 Oct 2014 10:16:30 +0200 (CEST) From: Patrick Georgi To: linux-tegra@vger.kernel.org Cc: Patrick Georgi Subject: [PATCH 3/5] data_layout: improve memory handling Date: Thu, 2 Oct 2014 10:16:26 +0200 Message-Id: <1412237788-20611-3-git-send-email-patrick@georgi-clan.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412237788-20611-1-git-send-email-patrick@georgi-clan.de> References: <1412237788-20611-1-git-send-email-patrick@georgi-clan.de> Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org - 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 --- src/data_layout.c | 6 ++++-- 1 file 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; }