-
Notifications
You must be signed in to change notification settings - Fork 3
Test malloc #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Test malloc #119
Changes from 28 commits
90031b5
0c277fd
c361e04
ed8950a
6d1817d
d7c93e9
b960740
256de6d
b6616ae
18377be
97bf9d1
5b72bc0
4834db8
c431142
2cfd0c0
e4b52b9
d07c743
052b64c
a6c22d8
32d7992
cd44116
7eaab09
82774d1
b64725b
5739a01
2088ce2
5a9936a
b4fa0eb
1a0e2bf
7979434
a2fa25c
fa8e4bf
07cb92a
c5339da
85ccdca
e83e97f
93329d9
873d70d
85d314d
a07917b
f2b9040
8f933c6
c908a60
829410b
09fe767
682f835
5286bc1
43653bb
e379875
11728ad
70c35a2
f18129e
fae9ae2
ce3b0ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,14 +46,15 @@ MiracastController *MiracastController::getInstance(MiracastError &error_code, M | |
|
|
||
| void MiracastController::destroyInstance() | ||
| { | ||
| MIRACASTLOG_TRACE("Entering..."); | ||
| MIRACASTLOG_INFO("Entering..."); | ||
| if (nullptr != m_miracast_ctrl_obj) | ||
| { | ||
| m_miracast_ctrl_obj->destroy_ControllerFramework(); | ||
| delete m_miracast_ctrl_obj; | ||
| m_miracast_ctrl_obj = nullptr; | ||
| } | ||
| MIRACASTLOG_TRACE("Exiting..."); | ||
|
|
||
| MIRACASTLOG_INFO("Exiting..."); | ||
| } | ||
|
|
||
| MiracastController::MiracastController(void) | ||
|
|
@@ -71,7 +72,7 @@ MiracastController::MiracastController(void) | |
|
|
||
| MiracastController::~MiracastController() | ||
| { | ||
| MIRACASTLOG_TRACE("Entering..."); | ||
| MIRACASTLOG_INFO("Entering..."); | ||
|
|
||
| while (!m_deviceInfoList.empty()) | ||
| { | ||
|
|
@@ -85,13 +86,17 @@ MiracastController::~MiracastController() | |
| m_groupInfo = nullptr; | ||
| } | ||
|
|
||
| MIRACASTLOG_TRACE("Exiting..."); | ||
|
|
||
|
|
||
| // ControllerThreadCallback(this); | ||
| //destroy_ControllerFramework(); | ||
| MIRACASTLOG_INFO("Exiting..."); | ||
| } | ||
|
|
||
| MiracastError MiracastController::create_ControllerFramework(std::string p2p_ctrl_iface) | ||
| { | ||
| MiracastError ret_code = MIRACAST_OK; | ||
| MIRACASTLOG_TRACE("Entering..."); | ||
| MIRACASTLOG_INFO("Entering...start controller thread"); | ||
|
|
||
| m_controller_thread = new MiracastThread(CONTROLLER_THREAD_NAME, | ||
| CONTROLLER_THREAD_STACK, | ||
|
|
@@ -503,7 +508,7 @@ void MiracastController::event_handler(P2P_EVENTS eventId, void *data, size_t le | |
| std::string event_buffer; | ||
| MIRACASTLOG_TRACE("Entering..."); | ||
|
|
||
| event_buffer = (char *)data; | ||
| event_buffer = static_cast<char*>(data); | ||
| free(data); | ||
|
|
||
| if ( false == m_start_discovering_enabled ) | ||
|
|
@@ -518,8 +523,8 @@ void MiracastController::event_handler(P2P_EVENTS eventId, void *data, size_t le | |
| controller_msgq_data.state = convertP2PtoSessionActions(eventId); | ||
| strncpy(controller_msgq_data.msg_buffer, event_buffer.c_str(), sizeof(controller_msgq_data.msg_buffer)); | ||
| controller_msgq_data.msg_buffer[sizeof(controller_msgq_data.msg_buffer) - 1] = '\0'; | ||
|
|
||
| MIRACASTLOG_INFO("event_handler to Controller Action[%#08X] buffer:%s ", controller_msgq_data.state, event_buffer.c_str()); | ||
| MIRACASTLOG_INFO("event_handler to Controller Action[%#08X] buffer:%s len %d", controller_msgq_data.state, event_buffer.c_str(),len); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coverity Issue - Invalid type in argument to printf format specifierArgument "len" to format specifier "%d" was expected to have type "int" but has type "unsigned long". Medium Impact, CWE-686 |
||
| m_controller_thread->send_message(&controller_msgq_data, sizeof(controller_msgq_data)); | ||
| MIRACASTLOG_VERBOSE("event received : %d buffer:%s ", eventId, event_buffer.c_str()); | ||
| } | ||
|
|
@@ -642,7 +647,7 @@ bool MiracastController::get_connection_status() | |
| void MiracastController::create_DeviceCacheData(std::string deviceMAC,std::string authType,std::string modelName,std::string deviceType, bool force_overwrite) | ||
| { | ||
| bool new_device_entry = false; | ||
| MIRACASTLOG_TRACE("Entering..."); | ||
| MIRACASTLOG_INFO("Entering..."); | ||
| DeviceInfo *cur_device_info_ptr = MiracastController::get_device_details(deviceMAC); | ||
|
|
||
| // Allocate memory and update the device cache info | ||
|
|
@@ -651,7 +656,7 @@ void MiracastController::create_DeviceCacheData(std::string deviceMAC,std::strin | |
| cur_device_info_ptr = new DeviceInfo; | ||
| new_device_entry = true; | ||
| force_overwrite = true; | ||
| MIRACASTLOG_VERBOSE("#### Creating Device Cache ####"); | ||
| MIRACASTLOG_INFO("#### Creating Device Cache ####"); | ||
| } | ||
|
|
||
| if (( nullptr != cur_device_info_ptr ) && (force_overwrite)) | ||
|
|
@@ -673,24 +678,25 @@ void MiracastController::create_DeviceCacheData(std::string deviceMAC,std::strin | |
| { | ||
| m_deviceInfoList.push_back(cur_device_info_ptr); | ||
| } | ||
| MIRACASTLOG_TRACE("Exiting..."); | ||
| MIRACASTLOG_INFO("Exiting..."); | ||
| } | ||
|
|
||
| DeviceInfo *MiracastController::get_device_details(std::string MAC) | ||
| { | ||
| DeviceInfo *deviceInfo = nullptr; | ||
| std::size_t found; | ||
| MIRACASTLOG_TRACE("Entering..."); | ||
| MIRACASTLOG_INFO("Entering..."); | ||
| for (auto device : m_deviceInfoList) | ||
| { | ||
| MIRACASTLOG_INFO("Entering device info list"); | ||
| found = device->deviceMAC.find(MAC); | ||
| if (found != std::string::npos) | ||
| { | ||
| deviceInfo = device; | ||
| break; | ||
| } | ||
| } | ||
| MIRACASTLOG_TRACE("Exiting..."); | ||
| MIRACASTLOG_INFO("Exiting..."); | ||
| return deviceInfo; | ||
| } | ||
|
|
||
|
|
@@ -784,19 +790,19 @@ void MiracastController::Controller_Thread(void *args) | |
| session_restart_required = false, | ||
| p2p_group_instance_alive = false; | ||
|
|
||
| MIRACASTLOG_TRACE("Entering..."); | ||
| MIRACASTLOG_INFO("Entering..."); | ||
|
|
||
| while (nullptr != m_controller_thread) | ||
| { | ||
| std::string event_buffer; | ||
| event_buffer.clear(); | ||
|
|
||
| MIRACASTLOG_TRACE("!!! Waiting for Event !!!\n"); | ||
| MIRACASTLOG_INFO("!!! Waiting for Event !!!\n"); | ||
| m_controller_thread->receive_message(&controller_msgq_data, CONTROLLER_MSGQ_SIZE, THREAD_RECV_MSG_INDEFINITE_WAIT); | ||
|
|
||
| event_buffer = controller_msgq_data.msg_buffer; | ||
|
|
||
| MIRACASTLOG_TRACE("!!! Received Action[%#08X]Data[%s] !!!\n", controller_msgq_data.state, event_buffer.c_str()); | ||
| MIRACASTLOG_INFO("!!! Received Action[%#08X]Data[%s] !!!\n", controller_msgq_data.state, event_buffer.c_str()); | ||
|
|
||
| if (CONTROLLER_SELF_ABORT == controller_msgq_data.state) | ||
| { | ||
|
|
@@ -1099,6 +1105,7 @@ void MiracastController::Controller_Thread(void *args) | |
| else | ||
| { | ||
| error_code = WPEFramework::Exchange::IMiracastService::REASON_CODE_GENERIC_FAILURE; | ||
| MIRACASTLOG_INFO("predebug session restart"); | ||
| session_restart_required = true; | ||
| MIRACASTLOG_ERROR("!!!! Unable to get the Source Device IP and Terminating Group Here !!!!"); | ||
| remove_P2PGroupInstance(); | ||
|
|
@@ -1247,6 +1254,7 @@ void MiracastController::Controller_Thread(void *args) | |
| } | ||
| new_thunder_req_client_connection_sent = false; | ||
| another_thunder_req_client_connection_sent = false; | ||
| MIRACASTLOG_INFO("predebug session_restart_required\n"); | ||
| session_restart_required = true; | ||
| p2p_group_instance_alive = false; | ||
| m_connect_req_notified = false; | ||
|
|
@@ -1605,10 +1613,10 @@ void ControllerThreadCallback(void *args) | |
| { | ||
| MiracastController *miracast_ctrler_obj = (MiracastController *)args; | ||
| MIRACASTLOG_TRACE("Entering..."); | ||
| sleep(1); | ||
| // sleep(1); | ||
| if ( nullptr != miracast_ctrler_obj ) | ||
| { | ||
| miracast_ctrler_obj->Controller_Thread(nullptr); | ||
| } | ||
| MIRACASTLOG_TRACE("Exiting..."); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,11 +48,15 @@ MiracastThread::MiracastThread(std::string thread_name, size_t stack_size, size_ | |
|
|
||
| MiracastThread::~MiracastThread() | ||
| { | ||
| MIRACASTLOG_TRACE("Entering..."); | ||
| MIRACASTLOG_INFO("Entering..."); | ||
|
|
||
| if ( 0 != m_pthread_id ){ | ||
| // Join thread | ||
| pthread_join(m_pthread_id, nullptr); | ||
| int ret = pthread_join(m_pthread_id, nullptr); | ||
| if (ret !=0) { | ||
| MIRACASTLOG_INFO("pthread join failed"); | ||
| } | ||
| MIRACASTLOG_INFO("Exit from joining..."); | ||
| m_pthread_id = 0; | ||
| pthread_attr_destroy(&m_pthread_attr); | ||
| } | ||
|
|
@@ -63,7 +67,7 @@ MiracastThread::~MiracastThread() | |
| sem_destroy(&m_empty_msgq_sem_obj); | ||
| m_g_queue = nullptr; | ||
| } | ||
| MIRACASTLOG_TRACE("Exiting..."); | ||
| MIRACASTLOG_INFO("Exiting..."); | ||
| } | ||
|
|
||
| MiracastError MiracastThread::start(void) | ||
|
|
@@ -84,20 +88,35 @@ MiracastError MiracastThread::start(void) | |
| void MiracastThread::send_message(void *message, size_t msg_size) | ||
| { | ||
| MIRACASTLOG_TRACE("Entering..."); | ||
|
|
||
| if (nullptr != m_g_queue){ | ||
| void *buffer = malloc(msg_size); | ||
| if (nullptr == buffer) | ||
|
|
||
| #if 0 | ||
| MIRACASTLOG_TRACE("msg size %d", msg_size); | ||
|
|
||
| void *buffer = malloc(msg_size); | ||
| if (nullptr == buffer) | ||
| { | ||
| MIRACASTLOG_ERROR("Memory Allocation Failed for %u\n", msg_size); | ||
| MIRACASTLOG_TRACE("Exiting..."); | ||
| return; | ||
| } | ||
| memset(buffer, 0x00, msg_size); | ||
| // Send message to queue | ||
|
|
||
| MIRACASTLOG_TRACE(""); | ||
| memcpy(buffer, message, msg_size); | ||
| g_async_queue_push(m_g_queue, buffer); | ||
| MIRACASTLOG_TRACE("copied"); | ||
| #endif | ||
| auto buffer = std::make_shared<std::vector<char>>((char*)message, (char*)message + msg_size); | ||
|
|
||
|
|
||
| // Allocate wrapper and push to queue | ||
| auto* wrapper = new std::shared_ptr<std::vector<char>>(buffer); | ||
|
||
| g_async_queue_push(m_g_queue, wrapper); | ||
| MIRACASTLOG_TRACE("pushed"); | ||
| sem_post(&m_empty_msgq_sem_obj); | ||
| MIRACASTLOG_TRACE("sempost"); | ||
|
|
||
| } | ||
| MIRACASTLOG_TRACE("Exiting..."); | ||
| } | ||
|
|
@@ -113,6 +132,7 @@ int8_t MiracastThread::receive_message(void *message, size_t msg_size, int sem_w | |
| int count = 0; | ||
| sem_getvalue(&m_empty_msgq_sem_obj,&count); | ||
| if ((0 < count ) || (THREAD_RECV_MSG_INDEFINITE_WAIT == sem_wait_timedout)){ | ||
|
|
||
| sem_wait(&m_empty_msgq_sem_obj); | ||
| status = true; | ||
| } | ||
|
|
@@ -135,14 +155,27 @@ int8_t MiracastThread::receive_message(void *message, size_t msg_size, int sem_w | |
|
|
||
| if (true == status) | ||
| { | ||
| void *data_ptr = static_cast<void *>(g_async_queue_pop(m_g_queue)); | ||
| auto* buffer_ptr = static_cast<std::shared_ptr<std::vector<char>>*>(data_ptr); | ||
| if (buffer_ptr && *buffer_ptr) { | ||
| std::shared_ptr<std::vector<char>> buffer = *buffer_ptr; | ||
| memcpy(message, buffer->data(), buffer->size()); | ||
| } | ||
| delete buffer_ptr; // Clean up the wrapper | ||
|
|
||
| } | ||
|
|
||
| #if 0 | ||
| void *data_ptr = static_cast<void *>(g_async_queue_pop(m_g_queue)); | ||
| if ((nullptr != message) && (nullptr != data_ptr)) | ||
| { | ||
| MIRACASTLOG_TRACE("dequeue..."); | ||
| memcpy(message, data_ptr, msg_size); | ||
| free(data_ptr); | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| MIRACASTLOG_TRACE("Exiting..."); | ||
| return status; | ||
| } | ||
|
|
@@ -398,4 +431,4 @@ void MessageQueue::detachQueue(void) | |
| m_condNotFull.notify_all(); | ||
|
|
||
| MIRACASTLOG_TRACE("Exiting..."); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity issue no longer present as of: undefined
Show issue
Coverity Issue - Uncaught exception
An exception of type "std::regex_error" is thrown but the exception specification "/implicit/noexcept" doesn't allow it to be thrown. This will result in a call to terminate().
Medium Impact, CWE-248
UNCAUGHT_EXCEPT