GPRS_C_SDK icon indicating copy to clipboard operation
GPRS_C_SDK copied to clipboard

SSL_Connect crash after connecting many times

Open Xoffio opened this issue 6 years ago • 3 comments

1. SDK version(SDK 版本)

{ V2.112 }


2. In what kind of operation problems appear, and how to reproduce the problem ?(什么样的操作步骤问题会出现,是否是稳定复现,如何复现问题?)

{

I have a code that will connect to a server with SSL. After approximate 8 min of connecting to a server, the function SSL_Connect crash giving me a error like the next one on coolwatcher:

Detected event: 0x9db00000 Detected event: 0x9db10000

GDB:

(gdb) bt
#0  0x81e04030 in memset ()
#1  0x8819adc9 in platform_calloc_uninit (n=<optimized out>, size=<optimized out>) at src/./mbedtls/library/platform.c:37
#2  0x8819f645 in mbedtls_ssl_setup (ssl=0x822491f0, conf=0x822492f4) at src/./mbedtls/library/ssl_tls.c:5617
#3  0x881906e9 in SSL_Connect (sslConfig=0x82273c78, ip=<optimized out>, port=<optimized out>) at src/api_ssl.c:245
#4  0x88240e69 in ?? ()
(gdb) bt f
#0  0x81e04030 in memset ()
No symbol table info available.
#1  0x8819adc9 in platform_calloc_uninit (n=<optimized out>, size=<optimized out>) at src/./mbedtls/library/platform.c:37
        p = <optimized out>
#2  0x8819f645 in mbedtls_ssl_setup (ssl=0x822491f0, conf=0x822492f4) at src/./mbedtls/library/ssl_tls.c:5617
        ret = <optimized out>
#3  0x881906e9 in SSL_Connect (sslConfig=0x82273c78, ip=<optimized out>, port=<optimized out>) at src/api_ssl.c:245
        error = <optimized out>
        ret = <optimized out>
#4  0x88240e69 in ?? ()
No symbol table info available.
(gdb) x/10i memset+124
   0x81e0401c <memset+124>:	addu	a0,v0,a0
   0x81e04020 <memset+128>:	srl	t1,a2,0x2
   0x81e04024 <memset+132>:	move	a3,a0
   0x81e04028 <memset+136>:	move	v1,t1
   0x81e0402c <memset+140>:	addiu	v1,v1,-1
=> 0x81e04030 <memset+144>:	sw	t0,0(a3)
   0x81e04034 <memset+148>:	bnez	v1,0x81e0402c <memset+140>
   0x81e04038 <memset+152>:	addiu	a3,a3,4
   0x81e0403c <memset+156>:	sll	t2,t1,0x2
   0x81e04040 <memset+160>:	andi	a2,a2,0x3

I think is a memory leak. By the release V2.112 in the updates note there is fix ssl reconnect memory leak bug but I think the bug still there.

My code is HERE

And some summary of my code:

     ...
     ...
     ...

//https POST
int Https_Post(const char* domain, const char* port,const char* path, const char* data, uint16_t dataLen, uint8_t* retBuffer, int bufferLen){
    const int bufferSize = 2048;

    int ret;
    SSL_Error_t error;
    SSL_Config_t config = {
        .caCert = ca_cert,
        .caCrl  = NULL,
        .clientCert = NULL,
        .clientKey  = NULL,
        .clientKeyPasswd = NULL,
        .hostName   = domain,
        .minVersion = SSL_VERSION_SSLv3,
        .maxVersion = SSL_VERSION_TLSv1_2,
        .verifyMode = SSL_VERIFY_MODE_OPTIONAL, // SSL_VERIFY_MODE_REQUIRED
        .entropyCustom = "GPRS"
    };

    // Build the package
    char* buffer = OS_Malloc(bufferSize);
    snprintf(buffer, bufferSize, "POST %s HTTP/1.1\r\nHost: %s\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n%s \r\n\r\n", path, domain, (dataLen-2), data);

    char* pData = buffer;
    Trace(1,"#LOG: Package: %s", pData);

    error = SSL_Init(&config);
    if(error != SSL_ERROR_NONE){
        Trace(1,"#LOG: ssl init error:%d",error);
        OS_Free(buffer);
        return -1;
    }
    else{
        // If SSL init, Connect to server
        error = SSL_Connect(&config, domain, port); // BUG HERE: crash after 8min aprox.
        if(error != SSL_ERROR_NONE){
            Trace(1,"#LOG: ssl connect error:%d",error);
            goto exit02;
        }

     ...
     ...
     ...

void SecondTask(void *pData){
    while(1){
            if(Https_Post(SERVER_IP, SERVER_PORT, SERVER_PATH_POST, locationBuffer, strlen(locationBuffer), buffer, bufferSize) < 0){
                Trace(1,"http get fail");
            }
}

     ...
     ...
     ...

// ----------------------------------------- Main task
void MainTask(void *pData){
    API_Event_t* event=NULL;

    // Create another task (secondary task).
    secondTaskHandle = OS_CreateTask(SecondTask,
        NULL, NULL, SECOND_TASK_STACK_SIZE, SECOND_TASK_PRIORITY, 0, 0, SECOND_TASK_NAME);

    while(1){
        // Wait for events from the lower system and is handle in EventDispatch
        if(OS_WaitEvent(mainTaskHandle, (void**)&event, OS_TIME_OUT_WAIT_FOREVER)){
            EventDispatch(event);
            OS_Free(event->pParam1);
            OS_Free(event->pParam2);
            OS_Free(event);
        }
    }
}

// ----------------------------------------- Main entrance
void shoes9G_Main(void){
    // Create the main task. It will return the pointer os that task.
    mainTaskHandle = OS_CreateTask(MainTask,
        NULL, NULL, MAIN_TASK_STACK_SIZE, MAIN_TASK_PRIORITY, 0, 0, MAIN_TASK_NAME);
    OS_SetUserMainHandle(&mainTaskHandle); // Set the main handle.
}

You can reproduce the same problem by compiling this project

}


Thanks you so much in advance.

Xoffio avatar Feb 05 '19 00:02 Xoffio

If it's a memory leak, you can try the latest version v2.129

Johhnzero avatar Jun 13 '19 10:06 Johhnzero

I'm with the same problem. Did you fix this issue?

ErichPetersen avatar Oct 04 '19 15:10 ErichPetersen

@Johhnzero can you please give the link for v2.129?

elangovan27sri avatar May 30 '23 10:05 elangovan27sri