diff --git a/devicemodel/hw/pci/core.c b/devicemodel/hw/pci/core.c index eeac295d3..ade97ad6d 100644 --- a/devicemodel/hw/pci/core.c +++ b/devicemodel/hw/pci/core.c @@ -750,7 +750,7 @@ pci_emul_alloc_pbar(struct pci_vdev *pdi, int idx, uint64_t hostbase, enum pcibar_type type, uint64_t size) { int error; - uint64_t *baseptr, limit, addr, mask, lobits, bar; + uint64_t *baseptr = NULL, limit = 0, addr, mask, lobits, bar; struct io_rsvd_rgn *region; if ((size & (size - 1)) != 0) diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c index c12a4cdcc..8714f3656 100644 --- a/devicemodel/hw/pci/xhci.c +++ b/devicemodel/hw/pci/xhci.c @@ -4270,7 +4270,7 @@ errout: static int pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts) { - char *s, *t, *n, *tptr; + char *s = NULL, *t, *n, *tptr; int i, rc = 0; struct pci_xhci_option_elem *elem; int (*f)(struct pci_xhci_vdev *, char *); @@ -4291,6 +4291,11 @@ pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts) } s = strdup(opts); + /*The first call of strtok_s need s should be specified string */ + if (!s) { + UPRINTF(LDBG, "options: strdup return NULL\n"); + goto errout; + } UPRINTF(LDBG, "options: %s\r\n", s); elem = xhci_option_table; @@ -4354,7 +4359,8 @@ errout: return rc; } - free(s); + if (s) + free(s); return xdev->ndevices; }