Skip to content

Commit b001596

Browse files
tianhuaswenlingz
authored andcommitted
dm: fix some potential memory leaks
This patch is to fix some potential memory leak issues 1, free mrp if the mmio_rb_lookup() function return 0; 2, free memory allocated by strdup in some error case handling. Tracked-On: #3277 Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent 0620980 commit b001596

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

devicemodel/core/mem.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ register_mem_int(struct mmio_rb_tree *rbt, struct mem_range *memp)
196196
struct mmio_rb_range *entry, *mrp;
197197
int err;
198198

199-
err = 0;
199+
err = -1;
200200

201201
mrp = malloc(sizeof(struct mmio_rb_range));
202202

@@ -210,8 +210,7 @@ register_mem_int(struct mmio_rb_tree *rbt, struct mem_range *memp)
210210
pthread_rwlock_unlock(&mmio_rwlock);
211211
if (err)
212212
free(mrp);
213-
} else
214-
err = -1;
213+
}
215214

216215
return err;
217216
}

devicemodel/hw/pci/xhci.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4126,6 +4126,8 @@ pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts)
41264126
free(xdev->portregs);
41274127
xdev->portregs = NULL;
41284128
}
4129+
if (rc < -2 && s)
4130+
free(s);
41294131
UPRINTF(LFTL, "fail to parse xHCI options, rc=%d\r\n", rc);
41304132

41314133
if (opts)

0 commit comments

Comments
 (0)