changeset 1151:100a0925f809

Fix a number of issues reported by cppcheck: http://lists.freediameter.net/pipermail/dev/2013-May/000214.html
author Sebastien Decugis <sdecugis@freediameter.net>
date Wed, 22 May 2013 15:37:48 +0200
parents fe4340e95815
children 7284e41faa46
files extensions/app_diameap/diameap_eap.c extensions/app_diameap/diameap_server.c extensions/app_diameap/diameap_tls.c libfdproto/dispatch.c
diffstat 4 files changed, 64 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/app_diameap/diameap_eap.c	Fri May 17 11:04:43 2013 +0800
+++ b/extensions/app_diameap/diameap_eap.c	Wed May 22 15:37:48 2013 +0200
@@ -91,13 +91,13 @@
 	TRACE_ENTRY("%p %p %p",eap_sm,eaptype,vendor);
 	*vendor = 0;
 	*eaptype = TYPE_NONE;
-	eap_sm->selectedMethod = NULL;
-
 	if (eap_sm == NULL)
 	{
 		return EINVAL;
 	}
 
+	eap_sm->selectedMethod = NULL;
+
 	if (eap_sm->user.userid == NULL)
 	{
 		if ((eap_sm->currentMethod == TYPE_NONE))
--- a/extensions/app_diameap/diameap_server.c	Fri May 17 11:04:43 2013 +0800
+++ b/extensions/app_diameap/diameap_server.c	Wed May 22 15:37:48 2013 +0200
@@ -1130,16 +1130,16 @@
 
 static void free_ans_attrib(struct avp_attribute * ans_attrib)
 {
-	if (ans_attrib->tofree == 1)
-	{
-		if(ans_attrib->value.os.data){
-		free(ans_attrib->value.os.data);
-		ans_attrib->value.os.data = NULL;
+	if(ans_attrib){
+		if (ans_attrib->tofree == 1)
+		{
+			if(ans_attrib->value.os.data){
+			free(ans_attrib->value.os.data);
+			ans_attrib->value.os.data = NULL;
+			}
 		}
-	}
-	if(ans_attrib){
-	free(ans_attrib);
-	ans_attrib = NULL;
+		free(ans_attrib);
+		ans_attrib = NULL;
 	}
 }
 
@@ -1184,64 +1184,64 @@
 static void diameap_free(struct diameap_state_machine * diameap_sm)
 {
 
-	if (diameap_sm->eap_sm.user.userid != NULL)
-	{
-		free(diameap_sm->eap_sm.user.userid);
-		diameap_sm->eap_sm.user.userid = NULL;
-	}
-
-	if (diameap_sm->eap_sm.user.password != NULL)
-	{
-		free(diameap_sm->eap_sm.user.password);
-		diameap_sm->eap_sm.user.password = NULL;
-	}
-
-	diameap_sm->eap_sm.selectedMethod = NULL;
-
-	if (diameap_sm->eap_sm.methodData != NULL)
+	if (diameap_sm != NULL)
 	{
-
-		struct plugin * cplugin;
-		if (diameap_plugin_get(diameap_sm->eap_sm.currentVendor,
-				diameap_sm->eap_sm.currentMethod, &cplugin))
+		if (diameap_sm->eap_sm.user.userid != NULL)
 		{
-			TRACE_DEBUG(INFO,"%sUnable to access EAP Method plugin {Type=%d, Vendor=%d}.",DIAMEAP_EXTENSION,diameap_sm->eap_sm.currentMethod,diameap_sm->eap_sm.currentVendor);
+			free(diameap_sm->eap_sm.user.userid);
+			diameap_sm->eap_sm.user.userid = NULL;
 		}
 
-		if (cplugin->eap_method_free)
+		if (diameap_sm->eap_sm.user.password != NULL)
 		{
-			(*cplugin->eap_method_free)(diameap_sm->eap_sm.methodData);
-			diameap_sm->eap_sm.methodData = NULL;
+			free(diameap_sm->eap_sm.user.password);
+			diameap_sm->eap_sm.user.password = NULL;
 		}
-		else
+
+		diameap_sm->eap_sm.selectedMethod = NULL;
+
+		if (diameap_sm->eap_sm.methodData != NULL)
 		{
-			TRACE_DEBUG(INFO,"%s[%s plugin] datafree function not available.",DIAMEAP_EXTENSION,cplugin->methodname);
-			if (diameap_sm->eap_sm.methodData != NULL)
+
+			struct plugin * cplugin;
+			if (diameap_plugin_get(diameap_sm->eap_sm.currentVendor,
+					diameap_sm->eap_sm.currentMethod, &cplugin))
 			{
-				free(diameap_sm->eap_sm.methodData);
+				TRACE_DEBUG(INFO,"%sUnable to access EAP Method plugin {Type=%d, Vendor=%d}.",DIAMEAP_EXTENSION,diameap_sm->eap_sm.currentMethod,diameap_sm->eap_sm.currentVendor);
+			}
+
+			if (cplugin->eap_method_free)
+			{
+				(*cplugin->eap_method_free)(diameap_sm->eap_sm.methodData);
 				diameap_sm->eap_sm.methodData = NULL;
 			}
-		}
-		if (diameap_sm->eap_sm.methodData)
-		{
-			TRACE_DEBUG(INFO,"%sSession state was not been freed correctly!!!",DIAMEAP_EXTENSION);
+			else
+			{
+				TRACE_DEBUG(INFO,"%s[%s plugin] datafree function not available.",DIAMEAP_EXTENSION,cplugin->methodname);
+				if (diameap_sm->eap_sm.methodData != NULL)
+				{
+					free(diameap_sm->eap_sm.methodData);
+					diameap_sm->eap_sm.methodData = NULL;
+				}
+			}
+			if (diameap_sm->eap_sm.methodData)
+			{
+				TRACE_DEBUG(INFO,"%sSession state was not been freed correctly!!!",DIAMEAP_EXTENSION);
+			}
 		}
-	}
-
-	if (diameap_sm->failedavp != NULL)
-	{
-		CHECK_FCT_DO(fd_msg_free(diameap_sm->failedavp), );
-	}
-
-	if (diameap_sm->lastReqEAPavp != NULL)
-	{
-		CHECK_FCT_DO(fd_msg_free(diameap_sm->lastReqEAPavp), );
-	}
-
-	CHECK_FCT_DO(diameap_unlink_attributes_lists(diameap_sm), );
-
-	if (diameap_sm != NULL)
-	{
+
+		if (diameap_sm->failedavp != NULL)
+		{
+			CHECK_FCT_DO(fd_msg_free(diameap_sm->failedavp), );
+		}
+
+		if (diameap_sm->lastReqEAPavp != NULL)
+		{
+			CHECK_FCT_DO(fd_msg_free(diameap_sm->lastReqEAPavp), );
+		}
+
+		CHECK_FCT_DO(diameap_unlink_attributes_lists(diameap_sm), );
+
 		free(diameap_sm);
 		diameap_sm = NULL;
 	}
--- a/extensions/app_diameap/diameap_tls.c	Fri May 17 11:04:43 2013 +0800
+++ b/extensions/app_diameap/diameap_tls.c	Wed May 22 15:37:48 2013 +0200
@@ -395,6 +395,8 @@
 	}
 	*/
 	fprintf(stderr, "-------------End Dump EAP-TLS msg-------------\n");
+	
+	free(data);
 }
 
 int diameap_tls_initialize(struct tls_data * data)
--- a/libfdproto/dispatch.c	Fri May 17 11:04:43 2013 +0800
+++ b/libfdproto/dispatch.c	Wed May 22 15:37:48 2013 +0200
@@ -122,7 +122,7 @@
 {
 	struct fd_list * cb_list = NULL;
 	struct disp_hdl * new;
-	struct dict_object * type_enum, * type_avp;
+	struct dict_object * type_enum = NULL, * type_avp;
 	struct dictionary  * dict = NULL;
 	
 	TRACE_ENTRY("%p %d %p %p", cb, how, when, handle);
@@ -149,7 +149,9 @@
 			CHECK_FCT( fd_dict_disp_cb(DICT_AVP, when->avp, &cb_list) );
 			if (dict) {
 				CHECK_FCT( fd_dict_search(dict, DICT_TYPE, TYPE_OF_AVP, when->avp, &type_avp, EINVAL) );
-				CHECK_PARAMS( type_enum == type_avp );
+				if (type_enum) {
+					CHECK_PARAMS( type_enum == type_avp );
+				}
 			}
 			break;
 		
"Welcome to our mercurial repository"