DM: fix memory leak

1. free memory allocated by strdup in blockif_open
2. free msix.table when its pci device deinit

Tracked-On: #2704
Signed-off-by: Minggui Cao <minggui.cao@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
Minggui Cao 2019-03-13 10:23:38 +08:00 committed by Eddie Dong
parent 436c30e4c5
commit 5397200118
2 changed files with 22 additions and 0 deletions

View File

@ -759,8 +759,18 @@ blockif_open(const char *optstr, const char *ident)
pthread_setname_np(bc->btid[i], tname);
}
/* free strdup memory */
if (nopt) {
free(nopt);
nopt = NULL;
}
return bc;
err:
/* handle failure case: free strdup memory*/
if (nopt)
free(nopt);
if (fd >= 0)
close(fd);
return NULL;

View File

@ -104,6 +104,7 @@ static void pci_lintr_route(struct pci_vdev *dev);
static void pci_lintr_update(struct pci_vdev *dev);
static void pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus, int slot,
int func, int coff, int bytes, uint32_t *val);
static void pci_emul_free_msixcap(struct pci_vdev *pdi);
static inline void
CFGWRITE(struct pci_vdev *dev, int coff, uint32_t val, int bytes)
@ -924,6 +925,7 @@ pci_emul_deinit(struct vmctx *ctx, struct pci_vdev_ops *ops, int bus, int slot,
if (fi->fi_devi) {
pci_lintr_release(fi->fi_devi);
pci_emul_free_bars(fi->fi_devi);
pci_emul_free_msixcap(fi->fi_devi);
free(fi->fi_devi);
}
}
@ -1030,6 +1032,16 @@ pci_emul_add_msixcap(struct pci_vdev *dev, int msgnum, int barnum)
sizeof(msixcap)));
}
static void
pci_emul_free_msixcap(struct pci_vdev *pdi)
{
if (pdi->msix.table) {
free(pdi->msix.table);
pdi->msix.table = NULL;
}
}
void
msixcap_cfgwrite(struct pci_vdev *dev, int capoff, int offset,
int bytes, uint32_t val)