Skip to content

Commit

Permalink
when netconn created directly,netconn_delete() will not call netconn_…
Browse files Browse the repository at this point in the history
…free(),

which will lead to memory leak

Closes #784
  • Loading branch information
zhangyanjiaoesp authored and igrr committed Dec 7, 2017
1 parent 22489d7 commit cc46b50
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion components/lwip/api/api_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cc46b50

Please sign in to comment.