From 05aa0ad114930a158ea0b0dae87366598cb3fa8f Mon Sep 17 00:00:00 2001 From: sg Date: Sat, 17 Jan 2015 21:54:17 +0100 Subject: [PATCH] netconn_delete(): check for errors returned by lwip_netconn_do_delconn() and don't call netconn_free() on error --- src/api/api_lib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 060a0306..b1e8d37b 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -113,6 +113,7 @@ netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_cal err_t netconn_delete(struct netconn *conn) { + err_t err; API_MSG_VAR_DECLARE(msg); /* No ASSERT here because possible to get a (conn == NULL) if we got an accept error */ @@ -123,12 +124,14 @@ netconn_delete(struct netconn *conn) API_MSG_VAR_ALLOC(msg); API_MSG_VAR_REF(msg).function = lwip_netconn_do_delconn; API_MSG_VAR_REF(msg).msg.conn = conn; - tcpip_apimsg(&API_MSG_VAR_REF(msg)); + err = tcpip_apimsg(&API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); - netconn_free(conn); + if (err != ERR_OK) { + return err; + } - /* don't care for return value of lwip_netconn_do_delconn since it only calls void functions */ + netconn_free(conn); return ERR_OK; }