Use os_memdup()

This leads to cleaner code overall, and also reduces the size
of the hostapd and wpa_supplicant binaries (in hwsim test build
on x86_64) by about 2.5 and 3.5KiB respectively.

The mechanical conversions all over the code were done with
the following spatch:

    @@
    expression SIZE, SRC;
    expression a;
    @@
    -a = os_malloc(SIZE);
    +a = os_memdup(SRC, SIZE);
    <...
    if (!a) {...}
    ...>
    -os_memcpy(a, SRC, SIZE);

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2017-03-07 10:17:23 +01:00 committed by Jouni Malinen
parent dbdda355d0
commit a1f11e34c4
73 changed files with 201 additions and 376 deletions

View file

@ -1173,12 +1173,11 @@ int p2p_find(struct p2p_data *p2p, unsigned int timeout,
p2p_free_req_dev_types(p2p);
if (req_dev_types && num_req_dev_types) {
p2p->req_dev_types = os_malloc(num_req_dev_types *
p2p->req_dev_types = os_memdup(req_dev_types,
num_req_dev_types *
WPS_DEV_TYPE_LEN);
if (p2p->req_dev_types == NULL)
return -1;
os_memcpy(p2p->req_dev_types, req_dev_types,
num_req_dev_types * WPS_DEV_TYPE_LEN);
p2p->num_req_dev_types = num_req_dev_types;
}
@ -4818,11 +4817,10 @@ int p2p_set_pref_chan(struct p2p_data *p2p, unsigned int num_pref_chan,
struct p2p_channel *n;
if (pref_chan) {
n = os_malloc(num_pref_chan * sizeof(struct p2p_channel));
n = os_memdup(pref_chan,
num_pref_chan * sizeof(struct p2p_channel));
if (n == NULL)
return -1;
os_memcpy(n, pref_chan,
num_pref_chan * sizeof(struct p2p_channel));
} else
n = NULL;