summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--block-qcow2.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/block-qcow2.c b/block-qcow2.c
index 9aa7261e3..d4556efa4 100644
--- a/block-qcow2.c
+++ b/block-qcow2.c
@@ -1809,6 +1809,12 @@ static int qcow_read_snapshots(BlockDriverState *bs)
int64_t offset;
uint32_t extra_data_size;
+ if (!s->nb_snapshots) {
+ s->snapshots = NULL;
+ s->snapshots_size = 0;
+ return 0;
+ }
+
offset = s->snapshots_offset;
s->snapshots = qemu_mallocz(s->nb_snapshots * sizeof(QCowSnapshot));
if (!s->snapshots)
@@ -2023,8 +2029,10 @@ static int qcow_snapshot_create(BlockDriverState *bs,
snapshots1 = qemu_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot));
if (!snapshots1)
goto fail;
- memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot));
- qemu_free(s->snapshots);
+ if (s->snapshots) {
+ memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot));
+ qemu_free(s->snapshots);
+ }
s->snapshots = snapshots1;
s->snapshots[s->nb_snapshots++] = *sn;