block/cow: Avoid use of uninitialized cow_bs in error path
commit6764579f894950afe87d8ec3b323adde8925d4fd
authorPeter Maydell <peter.maydell@linaro.org>
Mon, 30 Jun 2014 18:03:37 +0000 (30 19:03 +0100)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 1 Jul 2014 08:15:34 +0000 (1 10:15 +0200)
treebfa56bfa82c72c4fd5252f4950f578117835e3e6
parent4caf0fcd45db46920a6264b1621ae6adc772ef19
block/cow: Avoid use of uninitialized cow_bs in error path

Commit 25814e8987 introduced an error-exit code path which does
a "goto exit" before the cow_bs variable is initialized, meaning
we would call bdrv_unref() on an uninitialized variable and
likely segfault. Fix this by moving the NULL-initialization
to the top of the function and making the exit code path handle
the case where it is NULL.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/cow.c