This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CC3220SF:在 malloc 之后不调用 OtaArchive.c 中的 GetEntireFile free

Guru**** 2487425 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/1209615/cc3220sf-getentirefile-in-otaarchive-c-free-is-not-called-after-malloc

器件型号:CC3220SF

您好!

  我认为有一个记忆泄漏,请帮助确认

ti.com/simplelink_cc32xx_sdk_6_10_00_05_\source\ti\net\ota\source\OtaArchive.c 行:123

int16_t GetEntireFile(uint8_t *pRecvBuf, int16_t RecvBufLen, int16_t *ProcessedSize, uint32_t FileSize, char **pFile)
{
    int16_t        copyLen = 0;
    static bool    firstRun = TRUE;
    static int16_t TotalRecvBufLen = 0;
    
	if (firstRun)
    {
        TotalRecvBufLen = RecvBufLen;
        firstRun = FALSE;
        if (TotalRecvBufLen < FileSize)
        {
             /* verify that FileSize  not bigger then the max uint32_t value */
            if (FileSize >= (uint32_t)MaxUint32_t)
            {
                return ARCHIVE_STATUS_ERROR_BUNDLE_CMD_FILE_NAME_MAX_LEN;
            }
            /* Didn't receive the entire file in the first run. */
            /* Allocate a buffer in the size of the entire file and fill it in each round. */
            pTempBuf = (char*)malloc(FileSize+1);
            if (pTempBuf == NULL)
            {
                /* Allocation failed, return error. */
                return -1;
            }
            memcpy(pTempBuf, (char *)pRecvBuf, RecvBufLen);
            *ProcessedSize = RecvBufLen;

            /* didn't receive the entire file, try in the next packet */
            return GET_ENTIRE_FILE_CONTINUE;
        }
        else
        {
            /* Received the entire file in the first run. */
            /* No additional memory allocation is needed. */
            *ProcessedSize = FileSize;
            *pFile = (char *)pRecvBuf;
        }
    }
    else
    {
        /* Avoid exceeding buffer size (FileSize + 1) */
        if (RecvBufLen > ((FileSize + 1) -TotalRecvBufLen))
        {
            copyLen = ((FileSize + 1) -TotalRecvBufLen);
        }
        else
        {
            copyLen = RecvBufLen;
        }

        /* Copy the received buffer from where we stopped the previous copy */
        memcpy(&(pTempBuf[TotalRecvBufLen]), (char *)pRecvBuf, copyLen);

        *ProcessedSize = copyLen;
        TotalRecvBufLen += copyLen;

        if (TotalRecvBufLen < FileSize)
        {
            /* didn't receive the entire file, try in the next packet */
            return GET_ENTIRE_FILE_CONTINUE;
        }

        /* At this point we have the whole file */
        *pFile = (char *)pTempBuf;
    }

    /* Set static variables to initial values to allow retry in case of a warning during the OTA process */
    firstRun = TRUE;
    TotalRecvBufLen = 0;

    return GET_ENTIRE_FILE_DONE;
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    显然缓冲区没有被释放。 我想这就是你的意思。

    您是否对此进行了测试和验证?

    我们正在规划一个长期 SDK 不久,我们将尝试推动修补程序,但可能已经太晚了,所以我会在这里添加修补程序(一旦我们验证了错误和修补程序)。  

    Br、

    Kobi.

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    请注意、此操作的优先级较低-因为成功的 OTA 会随软复位结束、因此泄漏的影响仅与 OTA 处理开始但失败的极少数情况相关。