aboutsummaryrefslogtreecommitdiffstats
path: root/src/eap_peer/eap_methods.c
diff options
context:
space:
mode:
authorJouni Malinen <jouni@qca.qualcomm.com>2016-01-13 21:25:54 (GMT)
committerJouni Malinen <j@w1.fi>2016-01-13 21:30:25 (GMT)
commit49a26bb3e37ef7d3c9b8b55a5a331ae64a1cd0f3 (patch)
tree478920060b841fa12a0872e694e3a6a3eb869a48 /src/eap_peer/eap_methods.c
parent7ce56032516896498bfd3d6a2891e53cf7cd31fd (diff)
downloadhostap-49a26bb3e37ef7d3c9b8b55a5a331ae64a1cd0f3.zip
hostap-49a26bb3e37ef7d3c9b8b55a5a331ae64a1cd0f3.tar.gz
hostap-49a26bb3e37ef7d3c9b8b55a5a331ae64a1cd0f3.tar.bz2
EAP peer: Simplify EAP method registration call
Free the allocated structure in error cases to remove need for each EAP method to handle the error cases separately. Each registration function can simply do "return eap_peer_method_register(eap);" in the end of the function. Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
Diffstat (limited to 'src/eap_peer/eap_methods.c')
-rw-r--r--src/eap_peer/eap_methods.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/eap_peer/eap_methods.c b/src/eap_peer/eap_methods.c
index 1bdd81e..9747954 100644
--- a/src/eap_peer/eap_methods.c
+++ b/src/eap_peer/eap_methods.c
@@ -18,6 +18,8 @@
static struct eap_method *eap_methods = NULL;
+static void eap_peer_method_free(struct eap_method *method);
+
/**
* eap_peer_get_eap_method - Get EAP method based on type number
@@ -295,7 +297,7 @@ struct eap_method * eap_peer_method_alloc(int version, int vendor,
* eap_peer_method_free - Free EAP peer method structure
* @method: Method structure allocated with eap_peer_method_alloc()
*/
-void eap_peer_method_free(struct eap_method *method)
+static void eap_peer_method_free(struct eap_method *method)
{
os_free(method);
}
@@ -303,26 +305,31 @@ void eap_peer_method_free(struct eap_method *method)
/**
* eap_peer_method_register - Register an EAP peer method
- * @method: EAP method to register
+ * @method: EAP method to register from eap_peer_method_alloc()
* Returns: 0 on success, -1 on invalid method, or -2 if a matching EAP method
* has already been registered
*
* Each EAP peer method needs to call this function to register itself as a
- * supported EAP method.
+ * supported EAP method. The caller must not free the allocated method data
+ * regardless of the return value.
*/
int eap_peer_method_register(struct eap_method *method)
{
struct eap_method *m, *last = NULL;
if (method == NULL || method->name == NULL ||
- method->version != EAP_PEER_METHOD_INTERFACE_VERSION)
+ method->version != EAP_PEER_METHOD_INTERFACE_VERSION) {
+ eap_peer_method_free(method);
return -1;
+ }
for (m = eap_methods; m; m = m->next) {
if ((m->vendor == method->vendor &&
m->method == method->method) ||
- os_strcmp(m->name, method->name) == 0)
+ os_strcmp(m->name, method->name) == 0) {
+ eap_peer_method_free(method);
return -2;
+ }
last = m;
}