Skip to content

Commit

Permalink
Copy the mesh pointer within the closure
Browse files Browse the repository at this point in the history
Fix issue #297
  • Loading branch information
BlackEdder committed Aug 5, 2019
1 parent a1e536d commit 0b710b7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/painlessMeshConnection.cpp
Expand Up @@ -48,12 +48,12 @@ ICACHE_FLASH_ATTR MeshConnection::~MeshConnection() {

void MeshConnection::initTCPCallbacks() {
using namespace logger;
// Need to pass separate copy of this->mesh, because self->close() can
// invalidate the pointer, causing a segmentation fault when trying to access
// self->mesh afterwards
client->onDisconnect(
[self = this->shared_from_this(), m = this->mesh](void *arg,
AsyncClient *client) {
[self = this->shared_from_this()](void *arg, AsyncClient *client) {
// Making a copy of self->mesh pointer, because self->close() can
// invalidate the original pointer, causing a segmentation fault
// when trying to access self->mesh afterwards
auto m = self->mesh;
if (m->semaphoreTake()) {
Log(CONNECTION, "onDisconnect(): dropping %u now= %u\n", self->nodeId,
m->getNodeTime());
Expand Down

0 comments on commit 0b710b7

Please sign in to comment.