xmalloc checks if the size is valid before allocating
memory, and also if the allocation was successful.

Signed-off-by: Shashank Ram <r...@vmware.com>
---
 lib/netdev-windows.c | 14 ++------------
 lib/wmi.c            | 14 ++------------
 2 files changed, 4 insertions(+), 24 deletions(-)

diff --git a/lib/netdev-windows.c b/lib/netdev-windows.c
index 375cb32..f90a439 100644
--- a/lib/netdev-windows.c
+++ b/lib/netdev-windows.c
@@ -394,12 +394,7 @@ netdev_windows_arp_lookup(const struct netdev *netdev,
         return ENXIO;
     }

-    arp_table = (MIB_IPNETTABLE *) malloc(buffer_length);
-
-    if (arp_table == NULL) {
-        VLOG_ERR("Could not allocate memory for all the interfaces");
-        return ENXIO;
-    }
+    arp_table = (MIB_IPNETTABLE *) xmalloc(buffer_length);

     ret_val = GetIpNetTable(arp_table, &buffer_length, false);

@@ -443,12 +438,7 @@ netdev_windows_get_next_hop(const struct in_addr *host,
         return ENXIO;
     }

-    all_addr = (IP_ADAPTER_ADDRESSES *) malloc(buffer_length);
-
-    if (all_addr == NULL) {
-        VLOG_ERR("Could not allocate memory for all the interfaces");
-        return ENXIO;
-    }
+    all_addr = (IP_ADAPTER_ADDRESSES *) xmalloc(buffer_length);

     ret_val = GetAdaptersAddresses(AF_INET,
                                    GAA_FLAG_INCLUDE_PREFIX |
diff --git a/lib/wmi.c b/lib/wmi.c
index dba8022..e6dc63c 100644
--- a/lib/wmi.c
+++ b/lib/wmi.c
@@ -406,12 +406,7 @@ delete_wmi_port(char *name)
     wchar_t internal_port_query[WMI_QUERY_COUNT] = L"SELECT * from "
         L"Msvm_EthernetPortAllocationSettingData  WHERE ElementName = \"" ;

-    wide_name = malloc((strlen(name) + 1) * sizeof(wchar_t));
-    if (wide_name == NULL) {
-        VLOG_WARN("Could not allocate memory for wide string");
-        retval = false;
-        goto error;
-    }
+    wide_name = xmalloc((strlen(name) + 1) * sizeof(wchar_t));

     if (!tranform_wide(name, wide_name)) {
         retval = false;
@@ -693,12 +688,7 @@ create_wmi_port(char *name) {
     wchar_t internal_port_query[WMI_QUERY_COUNT] = L"SELECT * FROM "
     L"Msvm_InternalEthernetPort WHERE ElementName = \"";

-    wide_name = malloc((strlen(name) + 1) * sizeof(wchar_t));
-    if (wide_name == NULL) {
-        VLOG_WARN("Could not allocate memory for wide string");
-        retval = false;
-        goto error;
-    }
+    wide_name = xmalloc((strlen(name) + 1) * sizeof(wchar_t));

     if (!tranform_wide(name, wide_name)) {
         retval = false;
--
2.9.3.windows.2

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to