A small memory footprint AMQP implimentation

Dependents:   iothub_client_sample_amqp remote_monitoring simplesample_amqp

Revision:
23:1111ee8bcba4
Parent:
22:524bded3f7a8
Child:
25:1101516ee67d
diff -r 524bded3f7a8 -r 1111ee8bcba4 session.c
--- a/session.c	Thu Apr 06 14:11:27 2017 -0700
+++ b/session.c	Fri Apr 21 14:50:32 2017 -0700
@@ -620,7 +620,7 @@
 	else
 	{
 		/* Codes_SRS_SESSION_01_030: [session_create shall create a new session instance and return a non-NULL handle to it.] */
-		result = malloc(sizeof(SESSION_INSTANCE));
+		result = (SESSION_INSTANCE*)malloc(sizeof(SESSION_INSTANCE));
 		/* Codes_SRS_SESSION_01_042: [If allocating memory for the session fails, session_create shall fail and return NULL.] */
 		if (result != NULL)
 		{
@@ -673,7 +673,7 @@
 	}
 	else
 	{
-		result = malloc(sizeof(SESSION_INSTANCE));
+		result = (SESSION_INSTANCE*)malloc(sizeof(SESSION_INSTANCE));
 		if (result != NULL)
 		{
 			result->connection = connection;
@@ -972,6 +972,7 @@
 			/* Codes_SRS_SESSION_01_046: [An unused handle shall be assigned to the link endpoint.] */
 			handle selected_handle = 0;
 			size_t i;
+            size_t name_length;
 
 			for (i = 0; i < session_instance->link_endpoint_count; i++)
 			{
@@ -989,7 +990,8 @@
 			result->callback_context = NULL;
 			result->output_handle = selected_handle;
 			result->input_handle = 0xFFFFFFFF;
-			result->name = malloc(strlen(name) + 1);
+            name_length = strlen(name);
+			result->name = (char*)malloc(name_length + 1);
 			if (result->name == NULL)
 			{
 				/* Codes_SRS_SESSION_01_045: [If allocating memory for the link endpoint fails, session_create_link_endpoint shall fail and return NULL.] */
@@ -999,10 +1001,10 @@
 			else
 			{
 				LINK_ENDPOINT_INSTANCE** new_link_endpoints;
-				strcpy(result->name, name);
+				(void)memcpy(result->name, name, name_length + 1);
 				result->session = session;
 
-				new_link_endpoints = realloc(session_instance->link_endpoints, sizeof(LINK_ENDPOINT_INSTANCE*) * (session_instance->link_endpoint_count + 1));
+				new_link_endpoints = (LINK_ENDPOINT_INSTANCE**)realloc(session_instance->link_endpoints, sizeof(LINK_ENDPOINT_INSTANCE*) * (session_instance->link_endpoint_count + 1));
 				if (new_link_endpoints == NULL)
 				{
 					/* Codes_SRS_SESSION_01_045: [If allocating memory for the link endpoint fails, session_create_link_endpoint shall fail and return NULL.] */