spapr_pci: Fix memory leak of vmstate_spapr_pci

When VM migrate VMState of spapr_pci, the field(msi_devs) of spapr_pci
having a flag of VMS_ALLOC need to allocate memory. If the src doesn't free
memory of msi_devs in SaveStateEntry of spapr_pci after QEMUFile save
VMState of spapr_pci, it may result in memory leak of msi_devs. We add the
post_save func to free memory, which prevents memory leak.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Jinhao Gao <gaojinhao@huawei.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20201231061020.828-2-gaojinhao@huawei.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
This commit is contained in:
Jinhao Gao 2020-12-31 14:10:18 +08:00 committed by Dr. David Alan Gilbert
parent 2766043345
commit e6ddad1fd5
1 changed files with 11 additions and 0 deletions

View File

@ -2173,6 +2173,16 @@ static int spapr_pci_pre_save(void *opaque)
return 0; return 0;
} }
static int spapr_pci_post_save(void *opaque)
{
SpaprPhbState *sphb = opaque;
g_free(sphb->msi_devs);
sphb->msi_devs = NULL;
sphb->msi_devs_num = 0;
return 0;
}
static int spapr_pci_post_load(void *opaque, int version_id) static int spapr_pci_post_load(void *opaque, int version_id)
{ {
SpaprPhbState *sphb = opaque; SpaprPhbState *sphb = opaque;
@ -2205,6 +2215,7 @@ static const VMStateDescription vmstate_spapr_pci = {
.version_id = 2, .version_id = 2,
.minimum_version_id = 2, .minimum_version_id = 2,
.pre_save = spapr_pci_pre_save, .pre_save = spapr_pci_pre_save,
.post_save = spapr_pci_post_save,
.post_load = spapr_pci_post_load, .post_load = spapr_pci_post_load,
.fields = (VMStateField[]) { .fields = (VMStateField[]) {
VMSTATE_UINT64_EQUAL(buid, SpaprPhbState, NULL), VMSTATE_UINT64_EQUAL(buid, SpaprPhbState, NULL),