diff options
author | Inaky Perez-Gonzalez <inaky@linux.intel.com> | 2009-10-08 13:08:01 +0900 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-10-10 14:41:28 +0200 |
commit | 0a1ab23cfbc98530f6036d5714fa557724e8e1d6 (patch) | |
tree | ae825a721a79f96f9b01de8d286276edf18ca84e | |
parent | 3f97b2d8aa4f0633249fa3b1b8499de929d70b37 (diff) | |
download | connman-0a1ab23cfbc98530f6036d5714fa557724e8e1d6.tar.gz connman-0a1ab23cfbc98530f6036d5714fa557724e8e1d6.tar.bz2 connman-0a1ab23cfbc98530f6036d5714fa557724e8e1d6.zip |
Dynamically allocate wmxsdk device descriptors
This makes it easier to run electricfence on them to verify overruns.
-rw-r--r-- | plugins/iwmxsdk.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/plugins/iwmxsdk.c b/plugins/iwmxsdk.c index b7dee540..52437f50 100644 --- a/plugins/iwmxsdk.c +++ b/plugins/iwmxsdk.c @@ -24,6 +24,7 @@ #endif #include <stdio.h> +#include <stdlib.h> #include <errno.h> #include <string.h> #include <net/if.h> @@ -42,7 +43,7 @@ #include "iwmx.h" /* Yes, this is dirty; see above on IWMX_SDK_DEV_MAX*/ -static struct wmxsdk g_iwmx_sdk_devs[IWMX_SDK_DEV_MAX]; +static struct wmxsdk *g_iwmx_sdk_devs[IWMX_SDK_DEV_MAX]; static struct wmxsdk *deviceid_to_wmxsdk(WIMAX_API_DEVICE_ID *device_id) { @@ -814,13 +815,19 @@ static void iwmx_sdk_dev_add(unsigned idx, unsigned api_idx, const char *name) idx, IWMX_SDK_DEV_MAX); goto error_bug; } - wmxsdk = &g_iwmx_sdk_devs[idx]; - if (wmxsdk->dev != NULL) { + if (g_iwmx_sdk_devs[idx] != NULL) { connman_error("BUG! device index %u already enumerated?\n", idx); goto error_bug; } + wmxsdk = malloc(sizeof(*wmxsdk)); + if (wmxsdk == NULL) { + connman_error("Can't allocate %zu bytes\n", + sizeof(*wmxsdk)); + goto error_bug; + } + memset(wmxsdk, 0, sizeof(*wmxsdk)); wmxsdk_init(wmxsdk); /* @@ -863,6 +870,7 @@ static void iwmx_sdk_dev_add(unsigned idx, unsigned api_idx, const char *name) wmxsdk->ifname, result); goto error_dev_add; } + g_iwmx_sdk_devs[idx] = wmxsdk; return; error_dev_add: @@ -884,7 +892,7 @@ static void iwmx_sdk_dev_rm(unsigned idx) idx, IWMX_SDK_DEV_MAX); goto error_bug; } - wmxsdk = &g_iwmx_sdk_devs[idx]; + wmxsdk = g_iwmx_sdk_devs[idx]; if (wmxsdk->dev == NULL) { DBG("device index %u not enumerated? ignoring\n", idx); goto error_bug; @@ -894,6 +902,8 @@ static void iwmx_sdk_dev_rm(unsigned idx) wmxsdk->name[0] = 0; connman_device_unref(wmxsdk->dev); memset(wmxsdk, 0, sizeof(*wmxsdk)); + g_iwmx_sdk_devs[idx] = NULL; + free(wmxsdk); error_bug: return; } |