From e6a179ea32ca32a2254f9806c7ebc1b9d4c5cf56 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Sat, 3 Sep 2011 21:24:06 +0200 Subject: [PATCH] netconn_alloc(): return on invalid protocol instead of initializing mbox size to 0 --- src/api/api_msg.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 76ac49e7..903ea9e9 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -597,18 +597,16 @@ netconn_alloc(enum netconn_type t, netconn_callback callback) #endif /* LWIP_TCP */ default: LWIP_ASSERT("netconn_alloc: undefined netconn_type", 0); - break; + goto free_and_return; } #endif if (sys_sem_new(&conn->op_completed, 0) != ERR_OK) { - memp_free(MEMP_NETCONN, conn); - return NULL; + goto free_and_return; } if (sys_mbox_new(&conn->recvmbox, size) != ERR_OK) { sys_sem_free(&conn->op_completed); - memp_free(MEMP_NETCONN, conn); - return NULL; + goto free_and_return; } #if LWIP_TCP @@ -633,6 +631,9 @@ netconn_alloc(enum netconn_type t, netconn_callback callback) #endif /* LWIP_SO_RCVBUF */ conn->flags = 0; return conn; +free_and_return: + memp_free(MEMP_NETCONN, conn); + return NULL; } /**