A small memory footprint AMQP implimentation

Dependents:   iothub_client_sample_amqp remote_monitoring simplesample_amqp

Revision:
45:83b4eda4891c
Parent:
43:4c1e4e94cdd3
Child:
46:01f7ca900e07
--- a/connection.c	Tue Jun 26 19:14:57 2018 -0700
+++ b/connection.c	Thu Jul 12 18:09:41 2018 -0700
@@ -1986,24 +1986,32 @@
 
         /* Codes_S_R_S_CONNECTION_01_130: [The outgoing channel associated with the endpoint shall be released by removing the endpoint from the endpoint list.] */
         /* Codes_S_R_S_CONNECTION_01_131: [Any incoming channel number associated with the endpoint shall be released.] */
-        if ((i < connection->endpoint_count) && (i > 0))
+        if (i < connection->endpoint_count)
         {
-            ENDPOINT_HANDLE* new_endpoints;
-            (void)memmove(connection->endpoints + i, connection->endpoints + i + 1, sizeof(ENDPOINT_HANDLE) * (connection->endpoint_count - i - 1));
-
-            new_endpoints = (ENDPOINT_HANDLE*)realloc(connection->endpoints, (connection->endpoint_count - 1) * sizeof(ENDPOINT_HANDLE));
-            if (new_endpoints != NULL)
+            // endpoint found
+            if (connection->endpoint_count == 1)
+            {
+                free(connection->endpoints);
+                connection->endpoints = NULL;
+                connection->endpoint_count = 0;
+            }
+            else
             {
-                connection->endpoints = new_endpoints;
-            }
+                ENDPOINT_HANDLE* new_endpoints;
+
+                if ((connection->endpoint_count - i - 1) > 0)
+                {
+                    (void)memmove(connection->endpoints + i, connection->endpoints + i + 1, sizeof(ENDPOINT_HANDLE) * (connection->endpoint_count - i - 1));
+                }
 
-            connection->endpoint_count--;
-        }
-        else if (connection->endpoint_count == 1)
-        {
-            free(connection->endpoints);
-            connection->endpoints = NULL;
-            connection->endpoint_count = 0;
+                new_endpoints = (ENDPOINT_HANDLE*)realloc(connection->endpoints, (connection->endpoint_count - 1) * sizeof(ENDPOINT_HANDLE));
+                if (new_endpoints != NULL)
+                {
+                    connection->endpoints = new_endpoints;
+                }
+
+                connection->endpoint_count--;
+            }
         }
 
         free(endpoint);