Message ID | 20170519215938.7344-1-rams@vmware.com |
---|---|
State | Accepted |
Headers | show |
On 19 May 2017 at 14:59, Shashank Ram <rams@vmware.com> wrote: > xmalloc checks if the size is valid before allocating > memory, and also if the allocation was successful. > > Signed-off-by: Shashank Ram <rams@vmware.com> > Applied, thanks! > --- > 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 > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev >
On Fri, May 19, 2017 at 03:20:41PM -0700, Guru Shetty wrote: > On 19 May 2017 at 14:59, Shashank Ram <rams@vmware.com> wrote: > > > xmalloc checks if the size is valid before allocating > > memory, and also if the allocation was successful. > > > > Signed-off-by: Shashank Ram <rams@vmware.com> > > > Applied, thanks! Does this need any backporting?
Branch-2.7 at least please. Branch-2.6 and branch-2.5 does not have the wmi.c file > -----Original Message----- > From: ovs-dev-bounces@openvswitch.org [mailto:ovs-dev- > bounces@openvswitch.org] On Behalf Of Ben Pfaff > Sent: Saturday, May 20, 2017 1:52 AM > To: Guru Shetty <guru@ovn.org> > Cc: ovs dev <dev@openvswitch.org> > Subject: Re: [ovs-dev] [PATCH v2] Windows lib: Use xmalloc instead of malloc > > On Fri, May 19, 2017 at 03:20:41PM -0700, Guru Shetty wrote: > > On 19 May 2017 at 14:59, Shashank Ram <rams@vmware.com> wrote: > > > > > xmalloc checks if the size is valid before allocating memory, and > > > also if the allocation was successful. > > > > > > Signed-off-by: Shashank Ram <rams@vmware.com> > > > > > Applied, thanks! > > Does this need any backporting? > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
OK, I backported all the way to branch-2.5, dropping the wmi changes in 2.6 and 2.5. On Fri, May 19, 2017 at 10:56:33PM +0000, Alin Serdean wrote: > Branch-2.7 at least please. Branch-2.6 and branch-2.5 does not have the wmi.c file > > > -----Original Message----- > > From: ovs-dev-bounces@openvswitch.org [mailto:ovs-dev- > > bounces@openvswitch.org] On Behalf Of Ben Pfaff > > Sent: Saturday, May 20, 2017 1:52 AM > > To: Guru Shetty <guru@ovn.org> > > Cc: ovs dev <dev@openvswitch.org> > > Subject: Re: [ovs-dev] [PATCH v2] Windows lib: Use xmalloc instead of malloc > > > > On Fri, May 19, 2017 at 03:20:41PM -0700, Guru Shetty wrote: > > > On 19 May 2017 at 14:59, Shashank Ram <rams@vmware.com> wrote: > > > > > > > xmalloc checks if the size is valid before allocating memory, and > > > > also if the allocation was successful. > > > > > > > > Signed-off-by: Shashank Ram <rams@vmware.com> > > > > > > > Applied, thanks! > > > > Does this need any backporting? > > _______________________________________________ > > dev mailing list > > dev@openvswitch.org > > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
> -----Original Message----- > From: Ben Pfaff [mailto:blp@ovn.org] > Sent: Saturday, May 20, 2017 2:25 AM > To: Alin Serdean <aserdean@cloudbasesolutions.com> > Cc: Guru Shetty <guru@ovn.org>; ovs dev <dev@openvswitch.org> > Subject: Re: [ovs-dev] [PATCH v2] Windows lib: Use xmalloc instead of malloc > > OK, I backported all the way to branch-2.5, dropping the wmi changes in > 2.6 and 2.5. > [Alin Serdean] Thanks!
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;
xmalloc checks if the size is valid before allocating memory, and also if the allocation was successful. Signed-off-by: Shashank Ram <rams@vmware.com> --- lib/netdev-windows.c | 14 ++------------ lib/wmi.c | 14 ++------------ 2 files changed, 4 insertions(+), 24 deletions(-) -- 2.9.3.windows.2