[Model] IoTivity
[BinType] AP
[Customer] IoT-Core
[Issue#] CONPRO-1392
[Request] Robert Chudek / r.chudek
[Occurrence Version] n/a
[Problem] After calling CAcloseSslConnection there was a memory leak.
[Cause & Measure] Cause: After calling CAcloseSslConnection endpoint wasn't freed which led to memory leak.
[Checking Method] n/a
[Team] IoT Connection
[Developer] Robert Chudek / r.chudek
[Solution company] Samsung
[Change Type] bug fix
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/414
(cherry picked from
18a20af57324bc3d816a862e3aa5194712d2e237)
Change-Id: I283055bea913401c6c23953857b7ccfe5db3581b
Signed-off-by: Abhishek Sansanwal <abhishek.s94@samsung.com>
CAResult_t CAcloseSslConnection(const CAEndpoint_t *endpoint);
/**
+ * Close the DTLS session and free endpoint.
+ *
+ * @param[in] endpoint information of network address;
+ * CAcloseSslConnectionWrapper takes ownership of endpoint
+ *
+ * @retval ::CA_STATUS_OK Successful.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+CAResult_t CAcloseSslConnectionFreeEndpoint(CAEndpoint_t *endpoint);
+
+/**
* Close the TLS session using UUID
*
* @param[in] identity UUID of target device
CAResult_t CAcloseSslConnection(const CAEndpoint_t *endpoint);
/**
+ * Close the DTLS session and free endpoint.
+ *
+ * @param[in] endpoint information of network address;
+ * CAcloseSslConnectionWrapper takes ownership of endpoint
+ *
+ * @retval ::CA_STATUS_OK Successful.
+ * @retval ::CA_STATUS_FAILED Operation failed.
+ */
+CAResult_t CAcloseSslConnectionFreeEndpoint(CAEndpoint_t *endpoint);
+
+/**
* initialize mbedTLS library and other necessary initialization.
*
* @return 0 on success otherwise a positive error value.
return CA_STATUS_OK;
}
+CAResult_t CAcloseSslConnectionFreeEndpoint(CAEndpoint_t *endpoint)
+{
+ OIC_LOG_V(INFO, NET_SSL_TAG, "In %s", __func__);
+ VERIFY_NON_NULL_RET(endpoint, NET_SSL_TAG, "Param endpoint is NULL" , CA_STATUS_INVALID_PARAM);
+
+ CAResult_t ret = CAcloseSslConnection(endpoint);
+ OICFree(endpoint);
+
+ OIC_LOG_V(INFO, NET_SSL_TAG, "Out %s", __func__);
+ return ret;
+}
+
+
CAResult_t CAcloseSslConnectionUsingUuid(const uint8_t *identity, size_t idLength)
{
OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
#endif
#ifdef __WITH_DTLS__
+#ifndef SINGLE_THREAD
+ // CAcloseSslConnection returns CAResult_t instead of void*, but the size is the same and crash shouldn't occur
+ pthread_t ccThread;
+ pthread_attr_t attr;
+ int initAttrRes = -1;
+ int pthreadCreateRes = -1;
+ int detachStatusRes = -1;
+ int memoryAllocationRes = -1;
+
+ do
+ {
+ initAttrRes = pthread_attr_init(&attr);
+ if (initAttrRes != 0)
+ {
+ break;
+ }
+ CAEndpoint_t *localEndpointCpyPtr = OICMalloc(sizeof(CAEndpoint_t));
+
+ if(NULL == localEndpointCpyPtr)
+ {
+ memoryAllocationRes = -1;
+ break;
+ }
+ else
+ {
+ memoryAllocationRes = 0;
+ }
+
+ (*localEndpointCpyPtr) = localEndpoint;
+ // this piece of code is reached on the main thread
+ // CAcloseSslConnection might wait for too long (network + mutexes) and watchdog might kill it
+ // Asynchronous call protects this function from watchdog
+ pthreadCreateRes = pthread_create(&ccThread, &attr, (void *(*)(void*))&CAcloseSslConnectionFreeEndpoint, (void*)localEndpointCpyPtr);
+
+ if (pthreadCreateRes != 0)
+ {
+ break;
+ }
+ detachStatusRes = pthread_detach(ccThread);
+ }while (0);
+
+ // regardless of CAcloseSslConnection result, the function will continue and g_connectionCallback will be called
+ OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "CAcloseSslConnection pthread_init [%d], mem_alloc [%d] pthread_create [%d], pthread_detach [%d]",
+ initAttrRes, memoryAllocationRes, pthreadCreateRes, detachStatusRes);
+#else
CAcloseSslConnection(&localEndpoint);
#endif
+#endif
}
if (g_connectionCallback)