Commit 771f133989ae75f7a0c00731326e7a02cef643b0

Authored by aliguori
1 parent efb816c9

Fix error handling in net_client_init() (Mark McLoughlin)

We weren't freeing the name string everywhere.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7144 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 16 additions and 10 deletions
... ... @@ -1610,7 +1610,8 @@ int net_client_init(const char *device, const char *p)
1610 1610  
1611 1611 if (idx == -1 || nb_nics >= MAX_NICS) {
1612 1612 fprintf(stderr, "Too Many NICs\n");
1613   - return -1;
  1613 + ret = -1;
  1614 + goto out;
1614 1615 }
1615 1616 nd = &nd_table[idx];
1616 1617 macaddr = nd->macaddr;
... ... @@ -1624,7 +1625,8 @@ int net_client_init(const char *device, const char *p)
1624 1625 if (get_param_value(buf, sizeof(buf), "macaddr", p)) {
1625 1626 if (parse_macaddr(macaddr, buf) < 0) {
1626 1627 fprintf(stderr, "invalid syntax for ethernet address\n");
1627   - return -1;
  1628 + ret = -1;
  1629 + goto out;
1628 1630 }
1629 1631 }
1630 1632 if (get_param_value(buf, sizeof(buf), "model", p)) {
... ... @@ -1664,8 +1666,9 @@ int net_client_init(const char *device, const char *p)
1664 1666 port = strtol(p, &devname, 10);
1665 1667 devname++;
1666 1668 if (port < 1 || port > 65535) {
1667   - fprintf(stderr, "vmchannel wrong port number\n");
1668   - return -1;
  1669 + fprintf(stderr, "vmchannel wrong port number\n");
  1670 + ret = -1;
  1671 + goto out;
1669 1672 }
1670 1673 vmc = malloc(sizeof(struct VMChannel));
1671 1674 snprintf(name, 20, "vmchannel%ld", port);
... ... @@ -1673,7 +1676,8 @@ int net_client_init(const char *device, const char *p)
1673 1676 if (!vmc->hd) {
1674 1677 fprintf(stderr, "qemu: could not open vmchannel device"
1675 1678 "'%s'\n", devname);
1676   - return -1;
  1679 + ret = -1;
  1680 + goto out;
1677 1681 }
1678 1682 vmc->port = port;
1679 1683 slirp_add_exec(3, vmc->hd, 4, port);
... ... @@ -1687,7 +1691,8 @@ int net_client_init(const char *device, const char *p)
1687 1691 char ifname[64];
1688 1692 if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
1689 1693 fprintf(stderr, "tap: no interface name\n");
1690   - return -1;
  1694 + ret = -1;
  1695 + goto out;
1691 1696 }
1692 1697 vlan->nb_host_devs++;
1693 1698 ret = tap_win32_init(vlan, device, name, ifname);
... ... @@ -1734,7 +1739,8 @@ int net_client_init(const char *device, const char *p)
1734 1739 ret = net_socket_mcast_init(vlan, device, name, buf);
1735 1740 } else {
1736 1741 fprintf(stderr, "Unknown socket options: %s\n", p);
1737   - return -1;
  1742 + ret = -1;
  1743 + goto out;
1738 1744 }
1739 1745 vlan->nb_host_devs++;
1740 1746 } else
... ... @@ -1764,13 +1770,13 @@ int net_client_init(const char *device, const char *p)
1764 1770 #endif
1765 1771 {
1766 1772 fprintf(stderr, "Unknown network device: %s\n", device);
1767   - if (name)
1768   - free(name);
1769   - return -1;
  1773 + ret = -1;
  1774 + goto out;
1770 1775 }
1771 1776 if (ret < 0) {
1772 1777 fprintf(stderr, "Could not initialize device '%s'\n", device);
1773 1778 }
  1779 +out:
1774 1780 if (name)
1775 1781 free(name);
1776 1782 return ret;
... ...