diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h index d1f728eef..619356862 100644 --- a/libraries/ESP8266WiFi/src/include/ClientContext.h +++ b/libraries/ESP8266WiFi/src/include/ClientContext.h @@ -90,12 +90,15 @@ class ClientContext { } void unref() { - DEBUGV(":ur %d\r\n", _refcnt); - if(--_refcnt == 0) { - flush(); - close(); - if(_discard_cb) _discard_cb(_discard_cb_arg, this); - delete this; + if(this != 0) { + DEBUGV(":ur %d\r\n", _refcnt); + if(--_refcnt == 0) { + flush(); + close(); + if(_discard_cb) + _discard_cb(_discard_cb_arg, this); + delete this; + } } } diff --git a/libraries/ESP8266WiFi/src/include/UdpContext.h b/libraries/ESP8266WiFi/src/include/UdpContext.h index c86e050ed..f7cebc86c 100644 --- a/libraries/ESP8266WiFi/src/include/UdpContext.h +++ b/libraries/ESP8266WiFi/src/include/UdpContext.h @@ -77,10 +77,11 @@ public: void unref() { - DEBUGV(":ur %d\r\n", _refcnt); - if (--_refcnt == 0) - { - delete this; + if(this != 0) { + DEBUGV(":ur %d\r\n", _refcnt); + if(--_refcnt == 0) { + delete this; + } } }