Skip to content

Commit 5397200

Browse files
mgcaoEddie Dong
authored andcommitted
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>
1 parent 436c30e commit 5397200

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

devicemodel/hw/block_if.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,18 @@ blockif_open(const char *optstr, const char *ident)
759759
pthread_setname_np(bc->btid[i], tname);
760760
}
761761

762+
/* free strdup memory */
763+
if (nopt) {
764+
free(nopt);
765+
nopt = NULL;
766+
}
767+
762768
return bc;
763769
err:
770+
/* handle failure case: free strdup memory*/
771+
if (nopt)
772+
free(nopt);
773+
764774
if (fd >= 0)
765775
close(fd);
766776
return NULL;

devicemodel/hw/pci/core.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static void pci_lintr_route(struct pci_vdev *dev);
104104
static void pci_lintr_update(struct pci_vdev *dev);
105105
static void pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus, int slot,
106106
int func, int coff, int bytes, uint32_t *val);
107+
static void pci_emul_free_msixcap(struct pci_vdev *pdi);
107108

108109
static inline void
109110
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,
924925
if (fi->fi_devi) {
925926
pci_lintr_release(fi->fi_devi);
926927
pci_emul_free_bars(fi->fi_devi);
928+
pci_emul_free_msixcap(fi->fi_devi);
927929
free(fi->fi_devi);
928930
}
929931
}
@@ -1030,6 +1032,16 @@ pci_emul_add_msixcap(struct pci_vdev *dev, int msgnum, int barnum)
10301032
sizeof(msixcap)));
10311033
}
10321034

1035+
static void
1036+
pci_emul_free_msixcap(struct pci_vdev *pdi)
1037+
{
1038+
if (pdi->msix.table) {
1039+
free(pdi->msix.table);
1040+
pdi->msix.table = NULL;
1041+
}
1042+
}
1043+
1044+
10331045
void
10341046
msixcap_cfgwrite(struct pci_vdev *dev, int capoff, int offset,
10351047
int bytes, uint32_t val)

0 commit comments

Comments
 (0)