diff --git a/src/app/FTPServer.h b/src/app/FTPServer.h index ca498dc..e761f98 100644 --- a/src/app/FTPServer.h +++ b/src/app/FTPServer.h @@ -27,7 +27,7 @@ class FTPServer : public TCPServer { if (login != NULL) { - if (strlen(login) > 0) + if (strlen(login)) { _login = (char *)malloc((sizeof(char) * strlen(login)) + 1); strcpy(_login, login); @@ -36,7 +36,7 @@ class FTPServer : public TCPServer if (password != NULL) { - if (strlen(password) > 0) + if (strlen(password)) { _password = (char *)malloc((sizeof(char) * strlen(password)) + 1); strcpy(_password, password); @@ -53,7 +53,7 @@ class FTPServer : public TCPServer virtual ~FTPServer() { _dataServer.stop(); - free(_login); free(_password); + free(_login); free(_password); free(_FTPDir); } virtual void stop() @@ -67,7 +67,12 @@ class FTPServer : public TCPServer virtual void setFTPDir(const char *FTPDir) { - _FTPDir = FTPDir; + if(FTPDir) + { + free(_FTPDir); + _FTPDir = (char *)malloc((strlen(FTPDir) * sizeof(char)) + 1); + strcpy(_FTPDir, FTPDir); + } } protected: @@ -1028,7 +1033,7 @@ class FTPServer : public TCPServer char *_login; char *_password; - const char *_FTPDir = NULL; //Pointer to constant string and char * const is a constant pointer to string + char *_FTPDir = nullptr; uint16_t _dataPort; WiFiServer _dataServer; //In passive mode, the FTP server opens two different ports (one for the commands and the other for the data stream)