diff mbox

hw/block/m25p80: fix resource leak

Message ID 1467684998-12076-1-git-send-email-zhaoshenglong@huawei.com
State New
Headers show

Commit Message

Shannon Zhao July 5, 2016, 2:16 a.m. UTC
From: Shannon Zhao <shannon.zhao@linaro.org>


These two are spot by Coverity 1357232 and 1357233.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>

---
 hw/block/m25p80.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

-- 
2.0.4

Comments

Peter Maydell July 5, 2016, 12:59 p.m. UTC | #1
On 5 July 2016 at 03:16, Shannon Zhao <zhaoshenglong@huawei.com> wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>

>

> These two are spot by Coverity 1357232 and 1357233.

>

> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>




Applied to target-arm.next, thanks.

-- PMM
diff mbox

Patch

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index d9b2793..ca8c12c 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -459,12 +459,13 @@  static void blk_sync_complete(void *opaque, int ret)
 
 static void flash_sync_page(Flash *s, int page)
 {
-    QEMUIOVector *iov = g_new(QEMUIOVector, 1);
+    QEMUIOVector *iov;
 
     if (!s->blk || blk_is_read_only(s->blk)) {
         return;
     }
 
+    iov = g_new(QEMUIOVector, 1);
     qemu_iovec_init(iov, 1);
     qemu_iovec_add(iov, s->storage + page * s->pi->page_size,
                    s->pi->page_size);
@@ -474,13 +475,14 @@  static void flash_sync_page(Flash *s, int page)
 
 static inline void flash_sync_area(Flash *s, int64_t off, int64_t len)
 {
-    QEMUIOVector *iov = g_new(QEMUIOVector, 1);
+    QEMUIOVector *iov;
 
     if (!s->blk || blk_is_read_only(s->blk)) {
         return;
     }
 
     assert(!(len % BDRV_SECTOR_SIZE));
+    iov = g_new(QEMUIOVector, 1);
     qemu_iovec_init(iov, 1);
     qemu_iovec_add(iov, s->storage + off, len);
     blk_aio_pwritev(s->blk, off, iov, 0, blk_sync_complete, iov);