Skip to content

Commit

Permalink
Fix memory issue #270 because of network reconnection.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jul 8, 2023
1 parent a89c0ee commit 4ec521c
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 37 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP Mail Client",
"version": "3.1.14",
"version": "3.1.15",
"keywords": "communication, email, imap, smtp, esp32, esp8266, samd, arduino",
"description": "Arduino E-Mail Client Library to send, read and get incoming email notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino Devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP Mail Client

version=3.1.14
version=3.1.15

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ESP_MAIL_CLIENT_CPP

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ESP_MAIL_CLIENT_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_Client_Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#ifndef ESP_MAIL_VERSION

#define ESP_MAIL_VERSION "3.1.14"
#define ESP_MAIL_VERSION_NUM 30114
#define ESP_MAIL_VERSION "3.1.15"
#define ESP_MAIL_VERSION_NUM 30115

/* The inconsistent file version checking to prevent mixed versions compilation. */
#define VALID_VERSION_CHECK(ver) (ver == ESP_MAIL_VERSION_NUM)
Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Const.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ESP_MAIL_CONST_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define ESP_MAIL_ERROR_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ESP_MAIL_CONFIG_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

Expand Down
12 changes: 8 additions & 4 deletions src/ESP_Mail_IMAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#define ESP_MAIL_IMAP_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

/**
* Mail Client Arduino Library for Espressif's ESP32 and ESP8266, Raspberry Pi RP2040 Pico, and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module
*
* Created July 7, 2023
* Created July 8, 2023
*
* This library allows Espressif's ESP32, ESP8266, SAMD and RP2040 Pico devices to send and read Email through the SMTP and IMAP servers.
*
Expand Down Expand Up @@ -4930,8 +4930,12 @@ bool IMAPSession::handleConnection(Session_Config *session_config, IMAP_Data *im
return MailClient.handleIMAPError(this, TCP_CLIENT_ERROR_NOT_INITIALIZED, false);
}

if (connected())
MailClient.closeTCPSession((void *)this, false);
// Resources are also released if network disconnected.
if (!MailClient.reconnect(this))
return false;

// Need to close previous connection first to free resources.
MailClient.closeTCPSession((void *)this, false);

_session_cfg = session_config;
_imap_data = imap_data;
Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ESP_MAIL_PRINT_H_

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

Expand Down
12 changes: 8 additions & 4 deletions src/ESP_Mail_SMTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#define ESP_MAIL_SMTP_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

/**
* Mail Client Arduino Library for Espressif's ESP32 and ESP8266, Raspberry Pi RP2040 Pico, and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module
*
* Created July 7, 2023
* Created July 8, 2023
*
* This library allows Espressif's ESP32, ESP8266, SAMD and RP2040 Pico devices to send and read Email through the SMTP and IMAP servers.
*
Expand Down Expand Up @@ -3411,9 +3411,13 @@ bool SMTPSession::handleConnection(Session_Config *session_config, bool &ssl)
if (!client.isInitialized())
return MailClient.handleSMTPError(this, TCP_CLIENT_ERROR_NOT_INITIALIZED);
}

// Resources are also released if network disconnected.
if (!MailClient.reconnect(this))
return false;

if (connected())
MailClient.closeTCPSession((void *)this, true);
// Close previous connection first to free resources.
MailClient.closeTCPSession((void *)this, true);

_session_cfg = session_config;

Expand Down
2 changes: 1 addition & 1 deletion src/extras/MB_Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MB_Time_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/extras/RFC2047.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define RFC2047_CPP

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/extras/RFC2047.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define RFC2047_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30114)
#if !VALID_VERSION_CHECK(30115)
#error "Mixed versions compilation."
#endif

Expand Down
13 changes: 9 additions & 4 deletions src/wcs/esp32/ESP32_TCP_Client.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ESP32 TCP Client Library v2.0.12
* ESP32 TCP Client Library v2.0.13
*
* Created June 17, 2023
* Created July 8, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -152,14 +152,19 @@ void ESP32_TCP_Client::setInsecure()

bool ESP32_TCP_Client::ethLinkUp()
{
if (strcmp(ETH.localIP().toString().c_str(), "0.0.0.0") != 0)
if (validIP(ETH.localIP()))
{
ETH.linkUp();
return true;
}
return false;
}

bool ESP32_TCP_Client::validIP(IPAddress ip)
{
return strcmp(ip.toString().c_str(), "0.0.0.0") != 0;
}

void ESP32_TCP_Client::ethDNSWorkAround()
{
}
Expand All @@ -173,7 +178,7 @@ bool ESP32_TCP_Client::networkReady()

return networkStatus;
#else
return WiFi.status() == WL_CONNECTED || ethLinkUp();
return (WiFi.status() == WL_CONNECTED && validIP(WiFi.localIP())) || ethLinkUp();
#endif
}

Expand Down
10 changes: 8 additions & 2 deletions src/wcs/esp32/ESP32_TCP_Client.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ESP32 TCP Client Library v2.0.12
* ESP32 TCP Client Library v2.0.13
*
* Created June 17, 2023
* Created July 8, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -99,6 +99,12 @@ class ESP32_TCP_Client
*/
bool ethLinkUp();

/**
* Checking for valid IP.
* @return true for valid.
*/
bool validIP(IPAddress ip);

/**
* Ethernet DNS workaround.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/wcs/esp32/ESP32_WCS.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ESP32 WiFi Client Secure v2.0.5
* ESP32 WiFi Client Secure v2.0.6
*
* Created July 4, 2023
* Created July 8, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -390,7 +390,7 @@ bool ESP32_WCS::connected()
{

if (!_ssl->client)
return 0;
return false;

return _ssl->client->connected();
}
Expand Down
4 changes: 2 additions & 2 deletions src/wcs/esp32/ESP32_WCS.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ESP32 WiFi Client Secure v2.0.5
* ESP32 WiFi Client Secure v2.0.6
*
* Created July 4, 2023
* Created July 8, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down
11 changes: 8 additions & 3 deletions src/wcs/esp8266/ESP8266_TCP_Client.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
*
* ESP8266 TCP Client Library v2.0.13
* ESP8266 TCP Client Library v2.0.14
*
* Created June 17, 2023
* Created July 8, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -198,6 +198,11 @@ bool ESP8266_TCP_Client::ethLinkUp()
return ret;
}

bool ESP8266_TCP_Client::validIP(IPAddress ip)
{
return strcmp(ip.toString().c_str(), "0.0.0.0") != 0;
}

void ESP8266_TCP_Client::ethDNSWorkAround()
{

Expand Down Expand Up @@ -244,7 +249,7 @@ bool ESP8266_TCP_Client::networkReady()

return networkStatus;
#else
return WiFi.status() == WL_CONNECTED || ethLinkUp();
return (WiFi.status() == WL_CONNECTED && validIP(WiFi.localIP())) || ethLinkUp();
#endif
}

Expand Down
10 changes: 8 additions & 2 deletions src/wcs/esp8266/ESP8266_TCP_Client.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
*
* The Network Upgradable ESP8266 Secure TCP Client Class, ESP8266_TCP_Client.h v2.0.13
* The Network Upgradable ESP8266 Secure TCP Client Class, ESP8266_TCP_Client.h v2.0.14
*
* Created June 17, 2023
* Created July 8, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -96,6 +96,12 @@ class ESP8266_TCP_Client
*/
bool ethLinkUp();

/**
* Checking for valid IP.
* @return true for valid.
*/
bool validIP(IPAddress ip);

/**
* Ethernet DNS workaround.
*/
Expand Down

0 comments on commit 4ec521c

Please sign in to comment.