nopnop2002 / esp-idf-ftpClient

ftp client for esp-idf
37 stars 7 forks source link

Memory leak for write access #11

Open QM-lsq opened 2 months ago

QM-lsq commented 2 months ago

Excuse me, when using ftpClientAccess for write access will occur memory leak, how to deal with it?

QM-lsq commented 2 months ago

企业微信截图_17214594668003

企业微信截图_17214594405777

nopnop2002 commented 2 months ago

Check if HEAP keeps getting smaller forever.

    int counter = 0;
    uint32_t heap_size_start = esp_get_free_heap_size();
    uint32_t heap_size_min = heap_size_start;
    int err_code;
    static NetBuf_t* ftpClientData = NULL;
    while(1) {
        err_code = ftpClient->ftpClientAccess("hello.txt", FTP_CLIENT_FILE_WRITE, FTP_CLIENT_TEXT, ftpClientNetBuf, &ftpClientData);
        ESP_LOGI(TAG, "err_code=%d", err_code);
        uint32_t heap_size_current = esp_get_free_heap_size();
        if (heap_size_min > heap_size_current) heap_size_min = heap_size_current;
        counter++;
        printf("%d %ld --> %ld\n", counter, heap_size_start, heap_size_min);
        ftpClient->ftpClientClose(ftpClientData);
        vTaskDelay(100);
    }

In my environment(esp32), I settled on 190692.

2986 221020 --> 190692

This phenomenon is caused by the ESP-IDF background task.

ESP-IDF background tasks consume a certain amount of HEAP.

QM-lsq commented 2 months ago

I am very happy to receive your reply, according to your method for testing, running a certain number of times, really stable, thank you very much

QM-lsq commented 2 months ago

However, I have another question, when reading the file can be downloaded in sections? Or read a larger length at once, which currently looks like a maximum of 4096 bytes at a time。I look forward to hearing from you

nopnop2002 commented 2 months ago

This library always uses 4096 bytes of space.

https://github.com/nopnop2002/esp-idf-ftpClient/blob/master/components/ftpClient/FtpClient.c#L348

https://github.com/nopnop2002/esp-idf-ftpClient/blob/master/components/ftpClient/FtpClient.c#L501

https://github.com/nopnop2002/esp-idf-ftpClient/blob/master/components/ftpClient/FtpClient.c#L842

QM-lsq commented 2 months ago

Yes, I found this length configuration on line 36 of the file FtpClient.h, but it's not practical to use ESP32 for a full file download if the file is over 1MB or larger。 Is there any other way besides extending the length range of this value?

nopnop2002 commented 2 months ago

it's not practical to use ESP32 for a full file download if the file is over 1MB or larger

That is correct.

Is there any other way besides extending the length range of this value?

there is no.

when reading the file can be downloaded in sections?

It may be useful to have such a feature.

Your PR or your new repository would be most welcome.

I hope that many people will add new features based on my repository.

QM-lsq commented 2 months ago

Thank you very much for your reply

QM-lsq commented 2 months ago

Excuse me,If I wanted to send some Command like STOR, Is it possible to just use the sendCommand interface?

nopnop2002 commented 2 months ago

STOR is ftpClientPut().

sendCommand() is a static function and cannot be used.

QM-lsq commented 2 months ago

if I just want to send a STOR or a RETR Command, Which function can I use?

nopnop2002 commented 2 months ago

Which function can I use?

The available APIs are described in the README.

It is not possible to send only STOR or RETR commands.