]> granicus.if.org Git - esp-idf/commitdiff
when netconn created directly,netconn_delete() will not call netconn_free(),
authorzhangyanjiao <zhangyanjiao@espressif.com>
Mon, 4 Dec 2017 11:23:43 +0000 (19:23 +0800)
committerzhangyanjiao <zhangyanjiao@espressif.com>
Tue, 5 Dec 2017 02:42:37 +0000 (10:42 +0800)
which will lead to memory leak

Closes https://github.com/espressif/esp-idf/issues/784

components/lwip/api/api_lib.c

index dfe207f9648724dce9ba7e478589fd1d5ee48a8f..fd2ca16772ce9995599b001e0058cb2248d0ceda 100755 (executable)
@@ -136,6 +136,15 @@ netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_cal
   return conn;
 }
 
+static inline bool is_created_by_socket(struct netconn *conn)
+{
+#if LWIP_SOCKET
+  if (conn && (conn->socket != -1)) {
+    return true;
+  }
+#endif
+  return false;
+}
 /**
  * Close a netconn 'connection' and free its resources.
  * UDP and RAW connection are completely closed, TCP pcbs might still be in a waitstate
@@ -174,7 +183,12 @@ netconn_delete(struct netconn *conn)
     return err;
   }
 
-#if !ESP_THREAD_SAFE
+#if ESP_THREAD_SAFE
+  if (is_created_by_socket(conn) == false) {
+    LWIP_DEBUGF(ESP_THREAD_SAFE_DEBUG, ("netconn_delete - free conn\n"));
+    netconn_free(conn);
+  }
+#else
   LWIP_DEBUGF(ESP_THREAD_SAFE_DEBUG, ("netconn_delete - free conn\n"));
   netconn_free(conn);
 #endif