diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index d7889a38e4..c85258c09a 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1310,9 +1310,11 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, } } } - if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL)) + if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL) && + snaplist->snaps && snaplist->nsnaps) { qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps), virshSnapSorter); + } snaplist->nsnaps -= deleted; ret = g_steal_pointer(&snaplist);