Commit c8e68b43 authored by Kevin Wolf's avatar Kevin Wolf
Browse files

qemu-io: Don't leak pattern file in error path



qemu_io_alloc_from_file() needs to close the pattern file even if some
error occurred.

Setting f = NULL in the success path and checking it for NULL in the
error path isn't strictly necessary at this point, but let's do it
anyway in case someone later adds a 'goto error' after closing the file.

Coverity: CID 1405303
Fixes: 4d731510
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
parent 4e08bee4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -401,6 +401,7 @@ static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
    }

    fclose(f);
    f = NULL;

    if (len > pattern_len) {
        len -= pattern_len;
@@ -420,6 +421,9 @@ static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,

error:
    qemu_io_free(buf_origin);
    if (f) {
        fclose(f);
    }
    return NULL;
}